| 1 |
import React, { createContext, useContext, useReducer } from 'react'; |
| 2 |
|
| 3 |
// Prepare a dataLayer |
| 4 |
export const StateContext = createContext(); |
| 5 |
|
| 6 |
// Wrap our app and provide the Data layer |
| 7 |
export const StateProvider = ( { reducer, initialState, children } ) => ( |
| 8 |
<StateContext.Provider value={ useReducer( reducer, initialState ) }> |
| 9 |
{ children } |
| 10 |
</StateContext.Provider> |
| 11 |
); |
| 12 |
|
| 13 |
// Get information from the data layer |
| 14 |
export const useStateValue = () => useContext( StateContext ); |
| 15 |
|