3232
3333@pn .component
3434def AnimatedCard () -> pn .Element :
35- """Demonstrates ``Animated.View`` driven by ``AnimatedValue`` + ``use_memo ``."""
36- opacity = pn .use_memo ( lambda : pn . Animated . Value ( 0.0 ), [] )
37- scale = pn .use_memo ( lambda : pn . Animated . Value ( 0.9 ), [] )
35+ """Demonstrates ``Animated.View`` driven by ``use_animated_value ``."""
36+ opacity = pn .use_animated_value ( 0.0 )
37+ scale = pn .use_animated_value ( 0.9 )
3838
3939 def _enter () -> None :
4040 pn .Animated .parallel (
@@ -63,8 +63,11 @@ def _enter() -> None:
6363 )
6464
6565
66+ @pn .memo
6667@pn .component
6768def TypographyDemo () -> pn .Element :
69+ """Wrapped in [`pn.memo`][pythonnative.memo] so it skips re-render when parent state changes."""
70+ print ("[TypographyDemo] render (should only appear once)" )
6871 return pn .Column (
6972 pn .Text ("Headline" , style = {"font_size" : 28 , "font_weight" : "700" }),
7073 pn .Text (
@@ -84,6 +87,7 @@ def TypographyDemo() -> pn.Element:
8487 )
8588
8689
90+ @pn .memo
8791@pn .component
8892def BordersAndShadows () -> pn .Element :
8993 return pn .View (
@@ -96,6 +100,7 @@ def BordersAndShadows() -> pn.Element:
96100 )
97101
98102
103+ @pn .memo
99104@pn .component
100105def Chips () -> pn .Element :
101106 return pn .Row (
@@ -112,6 +117,20 @@ def Chips() -> pn.Element:
112117 )
113118
114119
120+ def section_heading (title : str , hint : str ) -> pn .Element :
121+ """Compose two sibling [`pn.Text`][pythonnative.Text] nodes via [`pn.Fragment`][pythonnative.Fragment].
122+
123+ Returning a Fragment from a plain helper (not a ``@pn.component``)
124+ lets the surrounding parent (here a [`pn.Column`][pythonnative.Column])
125+ flatten the siblings into its own child list without an extra
126+ wrapper view.
127+ """
128+ return pn .Fragment (
129+ pn .Text (title , style = styles ["section_title" ]),
130+ pn .Text (hint , style = styles ["hint" ]),
131+ )
132+
133+
115134@pn .component
116135def ShowcaseScreen () -> pn .Element :
117136 nav = pn .use_navigation ()
@@ -133,10 +152,10 @@ def go_back() -> None:
133152 pn .Column (
134153 pn .Text (message , style = styles ["title" ]),
135154 AnimatedCard (),
136- pn . Text ("Typography" , style = styles [ "section_title" ] ),
155+ section_heading ("Typography" , "Memoized via @pn.memo; renders only once." ),
137156 TypographyDemo (),
138157 BordersAndShadows (),
139- pn . Text ("Chips" , style = styles [ "section_title" ] ),
158+ section_heading ("Chips" , "Composed via pn.Fragment without an extra container." ),
140159 Chips (),
141160 pn .Pressable (
142161 pn .View (
0 commit comments