| 1 |
/** |
| 2 |
* WordPress dependencies. |
| 3 |
*/ |
| 4 |
import { createContext, useReducer, WPElement } from '@wordpress/element'; |
| 5 |
|
| 6 |
/** |
| 7 |
* Internal dependencies. |
| 8 |
*/ |
| 9 |
import { editorReducer, initialState } from './reducers/editorReducer'; |
| 10 |
|
| 11 |
const State = createContext(); |
| 12 |
const Dispatch = createContext(); |
| 13 |
|
| 14 |
/** |
| 15 |
* App Context. |
| 16 |
* |
| 17 |
* @param {object} props Props. |
| 18 |
* @returns {WPElement} AppContext component |
| 19 |
*/ |
| 20 |
const AppContext = (props) => { |
| 21 |
const { children } = props; |
| 22 |
const [state, dispatch] = useReducer(editorReducer, initialState); |
| 23 |
|
| 24 |
return ( |
| 25 |
<State.Provider value={state}> |
| 26 |
<Dispatch.Provider value={dispatch}>{children}</Dispatch.Provider> |
| 27 |
</State.Provider> |
| 28 |
); |
| 29 |
}; |
| 30 |
|
| 31 |
export { AppContext, State, Dispatch }; |
| 32 |
|