1- import React , { useState , useEffect } from 'react' ;
1+ import React , { useState , useEffect , useMemo } from 'react' ;
22import { Card , Typography , Space , Tag , Divider , Collapse , Tabs , Spin , Alert } from 'antd' ;
33import {
44 CheckCircleOutlined ,
@@ -14,6 +14,28 @@ import ReactMarkdown from 'react-markdown';
1414
1515const { Title, Text, Paragraph } = Typography ;
1616
17+ // Style constants to prevent recreation on every render
18+ const CONTAINER_STYLE = {
19+ height : '100%' ,
20+ display : 'flex' as const ,
21+ flexDirection : 'column' as const ,
22+ background : '#0f172a'
23+ } ;
24+
25+ const TABS_STYLE = {
26+ flex : 1 ,
27+ display : 'flex' as const ,
28+ flexDirection : 'column' as const
29+ } ;
30+
31+ const TAB_BAR_STYLE = {
32+ margin : '0 20px' ,
33+ paddingTop : '16px' ,
34+ marginBottom : 16 ,
35+ borderBottom : '1px solid rgba(148,163,184,0.14)' ,
36+ flexShrink : 0
37+ } ;
38+
1739interface Example {
1840 id : string ;
1941 category : string ;
@@ -32,6 +54,7 @@ const PromptExamples: React.FC = () => {
3254 const [ loading , setLoading ] = useState ( false ) ;
3355 const [ error , setError ] = useState < string | null > ( null ) ;
3456
57+ // Load markdown only once on mount
3558 useEffect ( ( ) => {
3659 const loadMarkdown = async ( ) => {
3760 setLoading ( true ) ;
@@ -331,7 +354,8 @@ class User(BaseModel):
331354 return acc ;
332355 } , { } as Record < string , Example [ ] > ) ;
333356
334- const tabItems = [
357+ // Memoize tabItems to prevent recreation on every render
358+ const tabItems = useMemo ( ( ) => [
335359 {
336360 key : 'builtin' ,
337361 label : (
@@ -636,33 +660,18 @@ class User(BaseModel):
636660 </ >
637661 ) ,
638662 } ,
639- ] ;
663+ ] , [ t , loading , error , markdownContent , groupedExamples , getLevelColor , getLevelText ] ) ;
640664
641665 return (
642- < div style = { {
643- height : '100%' ,
644- display : 'flex' ,
645- flexDirection : 'column' ,
646- background : '#0f172a'
647- } } >
666+ < div style = { CONTAINER_STYLE } >
648667 < Tabs
649668 defaultActiveKey = "builtin"
650669 items = { tabItems }
651- style = { {
652- flex : 1 ,
653- display : 'flex' ,
654- flexDirection : 'column'
655- } }
656- tabBarStyle = { {
657- margin : '0 20px' ,
658- paddingTop : '16px' ,
659- marginBottom : 16 ,
660- borderBottom : '1px solid rgba(148,163,184,0.14)' ,
661- flexShrink : 0
662- } }
670+ style = { TABS_STYLE }
671+ tabBarStyle = { TAB_BAR_STYLE }
663672 />
664673 </ div >
665674 ) ;
666675} ;
667676
668- export default PromptExamples ;
677+ export default React . memo ( PromptExamples ) ;
0 commit comments