File tree Expand file tree Collapse file tree 5 files changed +33
-0
lines changed Expand file tree Collapse file tree 5 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ <script >
2
+ </script >
Original file line number Diff line number Diff line change
1
+ import type { PageLoad } from "./$types"
2
+
3
+ export const load = ( async ( { params } ) => {
4
+ return {
5
+ title : "useCallback" ,
6
+ react : ( await import ( "./react.jsx?raw" ) ) . default ,
7
+ svelte : ( await import ( "./svelte.svelte?raw" ) ) . default ,
8
+ }
9
+ } ) satisfies PageLoad
Original file line number Diff line number Diff line change
1
+ // This function (component) is executed on every render
2
+ function Component ( ) {
3
+ // this event handler is redefined on every render
4
+ const handleClick = ( ) => alert ( "hello" )
5
+
6
+ // because `handleClick` is redefined on every render, `ChildComponent` will be re-rendered too. Because its `onClick` prop is considered changed.
7
+ return < ChildComponent onClick = { handleClick } />
8
+ }
Original file line number Diff line number Diff line change
1
+ <script >
2
+ // In Svelte this isn't needed, because event handlers are declared inside <script> tags.
3
+ // They aren't defined in the render path and therefore aren't redefined on every render.
4
+ // They are defined once per component, so they work similar to how event handlers worked with React.Component.
5
+ </script >
Original file line number Diff line number Diff line change 12
12
let tile3Url = " /useMemo"
13
13
let tile4Url = " /useRef"
14
14
let tile5Url = " /useReducer"
15
+ let tile6Url = " /useCallback"
15
16
</script >
16
17
17
18
<!-- App Shell -->
88
89
href ={tile5Url }
89
90
class ={tile5Url === $page .url .pathname ? " bg-primary-500" : " " }><Icon icon =" code" /></AppRailTile
90
91
>
92
+ <AppRailTile
93
+ label =" useCallback"
94
+ title =" useCallback"
95
+ value ={5 }
96
+ tag =" a"
97
+ href ={tile6Url }
98
+ class ={tile6Url === $page .url .pathname ? " bg-primary-500" : " " }><Icon icon =" code" /></AppRailTile
99
+ >
91
100
</svelte:fragment >
92
101
93
102
<svelte:fragment slot =" trail" >
You can’t perform that action at this time.
0 commit comments