Last active
February 25, 2020 01:52
-
-
Save csantiago132/e1634d440708ee5fbbb05e4bba63180c to your computer and use it in GitHub Desktop.
Revisions
-
csantiago132 revised this gist
Feb 25, 2020 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,8 @@ import * as React from 'react'; import reducer from './path to the object containing the reducers/'; import { combineReducer } from './path to combineReducer function'; const AppStateProvider = React.createContext({}); const ContextProvider = ({ children }) => { @@ -14,5 +18,9 @@ const ContextProvider = ({ children }) => { // pass in the returned value of useReducer const contextValue = React.useMemo(() => ({ state, dispatch }), [state, dispatch]); return <AppStateProvider.Provider value={contextValue}>{children}</AppStateProvider.Provider>; }; export { ContextProvider, AppStateProvider as ContextConsumer }; -
csantiago132 revised this gist
Feb 25, 2020 . No changes.There are no files selected for viewing
-
csantiago132 revised this gist
Feb 25, 2020 . 1 changed file with 12 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,18 @@ // ... prev. code ommited const ContextProvider = ({ children }) => { const reducers = React.useCallback(() => { return combineReducer(reducer); }, [combineReducer]); // call the function to get initial state and global reducer const [initialState, mainReducer] = reducers(); // setup useReducer with the returned value of the reducers function const [state, dispatch] = React.useReducer(mainReducer, initialState); // pass in the returned value of useReducer const contextValue = React.useMemo(() => ({ state, dispatch }), [state, dispatch]); }; -
csantiago132 revised this gist
Feb 25, 2020 . 1 changed file with 7 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,10 @@ // ... prev. code ommited const ContextProvider = ({ children }) => { const reducers = React.useCallback(() => { return combineReducer(reducer); }, [combineReducer]); } -
csantiago132 created this gist
Feb 25, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ import * as React from 'react'; import reducer from './path to the object containing the reducers/'; import { combineReducer } from './path to combineReducer function'; const AppStateProvider = React.createContext({}); const ContextProvider = ({ children }) => { }