Last active
September 17, 2020 13:03
-
-
Save stereobooster/405983056bc61a7f94c90bacf29f9b95 to your computer and use it in GitHub Desktop.
Revisions
-
stereobooster revised this gist
Sep 17, 2020 . 1 changed file with 1 addition and 0 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 @@ -8,6 +8,7 @@ const reducer = (oldState, action) => { // useState is simplified useReducer const useState = (initialState, init) => { // it returns [state, dispatch] // dispatch === setState in this case, because of the way we implemented reducer return useReducer(reducer, initialState, init); } -
stereobooster revised this gist
Sep 17, 2020 . 1 changed file with 2 additions and 3 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 @@ -8,9 +8,8 @@ const reducer = (oldState, action) => { // useState is simplified useReducer const useState = (initialState, init) => { // dispatch === setState in this case, because of the way we implemented reducer return useReducer(reducer, initialState, init); } // useCallback is simplified useMemo -
stereobooster revised this gist
Sep 17, 2020 . 1 changed file with 1 addition 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 @@ -9,7 +9,7 @@ const reducer = (oldState, action) => { // useState is simplified useReducer const useState = (initialState, init) => { const [state, dispatch] = useReducer(reducer, initialState, init); const setState = dispatch; return [state, setState]; } -
stereobooster created this gist
Sep 17, 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,19 @@ const reducer = (oldState, action) => { if (typeof action === "function") { return action(oldState) } else { return action; } } // useState is simplified useReducer const useState = (initialState, init) => { const [state, dispatch] = useReducer(reducer, initialState, init); const setState = useCallback((newState) => dispatch(newState), [dispatch]) return [state, setState]; } // useCallback is simplified useMemo const useCallback = (callback, dependencies) => { return useMemo(() => callback, dependencies); }