File tree Expand file tree Collapse file tree 5 files changed +62
-0
lines changed Expand file tree Collapse file tree 5 files changed +62
-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 : "useReducer" ,
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
+ import React , { useReducer } from 'react'
2
+
3
+ const initialState = { count : 0 }
4
+
5
+ function reducer ( state , action ) {
6
+ switch ( action . type ) {
7
+ case 'increment' :
8
+ return { count : state . count + 1 }
9
+ case 'decrement' :
10
+ return { count : state . count - 1 }
11
+ default :
12
+ throw new Error ( )
13
+ }
14
+ }
15
+
16
+ export default function Counter ( ) {
17
+ const [ state , dispatch ] = useReducer ( reducer , initialState )
18
+ return (
19
+ < >
20
+ Count: { state . count }
21
+ < button onClick = { ( ) => dispatch ( { type : 'decrement' } ) } > -</ button >
22
+ < button onClick = { ( ) => dispatch ( { type : 'increment' } ) } > +</ button >
23
+ </ >
24
+ )
25
+ }
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import { writable } from " svelte/store"
3
+
4
+ const initialValue = 0
5
+ const count = writable (initialValue)
6
+
7
+ count .increment = () => {
8
+ count .update ((state ) => state + 1 )
9
+ }
10
+ count .decrement = () => {
11
+ count .update ((state ) => state - 1 )
12
+ }
13
+ </script >
14
+
15
+ Count: {$count }
16
+ <button on:click ={count .decrement }>-</button >
17
+ <button on:click ={count .increment }>+</button >
Original file line number Diff line number Diff line change 11
11
let tile2Url = " /useEffect"
12
12
let tile3Url = " /useMemo"
13
13
let tile4Url = " /useRef"
14
+ let tile5Url = " /useReducer"
14
15
</script >
15
16
16
17
<!-- App Shell -->
79
80
href ={tile4Url }
80
81
class ={tile4Url === $page .url .pathname ? " bg-primary-500" : " " }><Icon icon =" code" /></AppRailTile
81
82
>
83
+ <AppRailTile
84
+ label =" useReducer"
85
+ title =" useReducer"
86
+ value ={4 }
87
+ tag =" a"
88
+ href ={tile5Url }
89
+ class ={tile5Url === $page .url .pathname ? " bg-primary-500" : " " }><Icon icon =" code" /></AppRailTile
90
+ >
82
91
</svelte:fragment >
83
92
84
93
<svelte:fragment slot =" trail" >
You can’t perform that action at this time.
0 commit comments