Last active
September 17, 2020 13:03
-
-
Save stereobooster/405983056bc61a7f94c90bacf29f9b95 to your computer and use it in GitHub Desktop.
This file contains 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 characters
const reducer = (oldState, action) => { | |
if (typeof action === "function") { | |
return action(oldState) | |
} else { | |
return 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); | |
} | |
// useCallback is simplified useMemo | |
const useCallback = (callback, dependencies) => { | |
return useMemo(() => callback, dependencies); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment