forked from JMU-CIME/CPR-Music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.js
66 lines (55 loc) · 1.9 KB
/
store.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { useMemo } from 'react';
import { createStore, applyMiddleware } from 'redux';
// import { composeWithDevTools } from 'redux-devtools-extension'
import thunkMiddleware from 'redux-thunk';
import reducers from './reducers';
import { createWrapper } from 'next-redux-wrapper';
// const reducer = (state, action) => {
// if (action.type === HYDRATE) {
// console.log(state, action);
// const nextState = {
// ...state, // use previous state
// ...action.payload, // apply delta from hydration
// };
// if (state.courses) nextState.courses = state.courses; // preserve count value on client side navigation
// return nextState;
// } else {
// return reducers(state, action);
// }
// };
// create a makeStore function
const makeStore = (context) => {
return createStore(reducers, applyMiddleware(thunkMiddleware));
};
// export an assembled wrapper
export const wrapper = createWrapper(makeStore, { debug: true });
// let store
// function initStore(initialState) {
// return createStore(
// reducers,
// initialState,
// (applyMiddleware(thunkMiddleware)
// )
// }
// export const initializeStore = (preloadedState) => {
// let _store = store ?? initStore(preloadedState)
// // After navigating to a page with an initial Redux state, merge that state
// // with the current state in the store, and create a new store
// if (preloadedState && store) {
// _store = initStore({
// ...store.getState(),
// ...preloadedState,
// })
// // Reset the current store
// store = undefined
// }
// // For SSG and SSR always create a new store
// if (typeof window === 'undefined') return _store
// // Create the store once in the client
// if (!store) store = _store
// return _store
// }
// export function useStore(initialState) {
// const store = useMemo(() => initializeStore(initialState), [initialState])
// return store
// }