@@ -23,35 +23,36 @@ For example:
23
23
``` ts title="/context/counter.ts"
24
24
import { createContext } from " solid-js" ;
25
25
26
- export const DEFAULT_COUNT = 0
27
- const INTIAL_STORE_SETTER = {
28
- increment : () => void ,
29
- decrement : () => void
26
+ export const INITIAL_COUNT = 0 ;
27
+
28
+ const INITIAL_STORE_SETTER = {
29
+ increment : () => {},
30
+ decrement : () => {}
30
31
};
31
32
32
33
export const CounterContext = createContext ([
33
34
{ count: INITIAL_COUNT },
34
- INTIAL_STORE_SETTER
35
+ INITIAL_STORE_SETTER
35
36
]);
36
37
```
37
38
38
39
With the context created in its own module, you can use to instantiate the context provider.
39
40
40
41
``` ts title="/context/counter-component.tsx"
41
42
import { createStore } from ' solid-js/store' ;
42
- import { CounterContext , DEFAULT_COUNT } from " ./counter.ts" ;
43
+ import { CounterContext , INITIAL_COUNT } from " ./counter.ts" ;
43
44
44
45
export function CounterProvider(props ) {
45
- const [value, setValue] = createStore ({ count: props .initialCount || DEFAULT_COUNT })
46
+ const [value, setValue] = createStore ({ count: props .initialCount || INITIAL_COUNT })
46
47
47
- const counter = [
48
+ const counter = [
48
49
value ,
49
50
{
50
51
increment() {
51
52
setValue (" count" , currentCount => currentCount + 1 )
52
53
},
53
54
decrement() {
54
- setValue (" count" , currentcount => currentCount - 1 )
55
+ setValue (" count" , currentCount => currentCount - 1 )
55
56
},
56
57
},
57
58
]
@@ -98,4 +99,4 @@ interface Context<T> {
98
99
}
99
100
100
101
function createContext<T >(defaultValue ? : T ): Context <T | undefined >
101
- ```
102
+ ```
0 commit comments