29 lines
804 B
JavaScript
29 lines
804 B
JavaScript
|
import React, { useReducer, useMemo } from "react";
|
||
|
import {
|
||
|
ApplicationStateContext,
|
||
|
ApplicationDispatchContext
|
||
|
} from "../state/ApplicationContexts";
|
||
|
import {
|
||
|
reducer,
|
||
|
dispatchActions as reducerDispatchActions
|
||
|
} from "../state/reducer";
|
||
|
import { initialState } from "../state/initialState";
|
||
|
|
||
|
const ApplicationStateProvider = ({ children }) => {
|
||
|
const [state, dispatch] = useReducer(reducer, initialState);
|
||
|
const dispatchActions = useMemo(
|
||
|
() => reducerDispatchActions(dispatch),
|
||
|
[dispatch]
|
||
|
);
|
||
|
|
||
|
return (
|
||
|
<ApplicationStateContext.Provider value={state}>
|
||
|
<ApplicationDispatchContext.Provider value={dispatchActions}>
|
||
|
{children}
|
||
|
</ApplicationDispatchContext.Provider>
|
||
|
</ApplicationStateContext.Provider>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
export default ApplicationStateProvider;
|