Newer
Older
Vinícius de Lima Gonçalves
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React from 'react'
export const Store = React.createContext()
const initialState = {
searchOpen: false,
search: {
query: '*',
class: 'LearningObject'
},
windowSize: {
width: 0,
height: 0
}
}
function reducer(state, action) {
switch (action.type){
case 'SAVE_SEARCH':
return {
...state,
search: action.newSearch
}
case 'HANDLE_SEARCH_BAR':
return {
...state,
searchOpen: action.opened
}
case 'WINDOW_SIZE':
return {
...state,
windowSize: action.innerWindow
}
default:
return state
}
}
export function StoreProvider(props) {
const [state, dispatch] = React.useReducer(reducer, initialState);
const value = { state, dispatch };
return (
<Store.Provider value={value}>
{props.children}
</Store.Provider>
)
}