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 : (
@@ -341,8 +365,7 @@ class User(BaseModel):
341365 </ Space >
342366 ) ,
343367 children : (
344- < div style = { { height : '100%' , overflow : 'auto' , overflowY : 'scroll' , paddingBottom : '40px' } } >
345- < Space direction = "vertical" size = "large" style = { { width : '100%' } } >
368+ < Space direction = "vertical" size = "large" style = { { width : '100%' } } >
346369 < Card
347370 size = "small"
348371 style = { { background : 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)' , border : 'none' } }
@@ -464,8 +487,7 @@ class User(BaseModel):
464487 </ Space >
465488 </ div >
466489 ) ) }
467- </ Space >
468- </ div >
490+ </ Space >
469491 ) ,
470492 } ,
471493 {
@@ -477,7 +499,7 @@ class User(BaseModel):
477499 </ Space >
478500 ) ,
479501 children : (
480- < div style = { { width : '100%' , height : '100%' , overflow : 'auto' , overflowY : 'scroll' , paddingBottom : '40px' } } >
502+ < >
481503 { loading && (
482504 < div style = { { textAlign : 'center' , padding : '40px' } } >
483505 < Spin size = "large" />
@@ -635,31 +657,21 @@ class User(BaseModel):
635657 </ div >
636658 </ Card >
637659 ) }
638- </ div >
660+ </ >
639661 ) ,
640662 } ,
641- ] ;
663+ ] , [ t , loading , error , markdownContent , groupedExamples , getLevelColor , getLevelText ] ) ;
642664
643665 return (
644- < div style = { {
645- height : '100%' ,
646- overflow : 'auto' ,
647- overflowY : 'scroll' ,
648- padding : '16px 20px' ,
649- paddingBottom : '40px' ,
650- background : '#0f172a'
651- } } >
666+ < div style = { CONTAINER_STYLE } >
652667 < Tabs
653668 defaultActiveKey = "builtin"
654669 items = { tabItems }
655- style = { { height : '100%' } }
656- tabBarStyle = { {
657- marginBottom : 16 ,
658- borderBottom : '1px solid rgba(148,163,184,0.14)' ,
659- } }
670+ style = { TABS_STYLE }
671+ tabBarStyle = { TAB_BAR_STYLE }
660672 />
661673 </ div >
662674 ) ;
663675} ;
664676
665- export default PromptExamples ;
677+ export default React . memo ( PromptExamples ) ;
0 commit comments