Created
October 28, 2019 14:50
-
-
Save csenio/70b8442cca704738df8d19cd3caa8de4 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
import {useReducer, useCallback} from 'react' | |
import produce from 'immer' | |
const useImmerReducer = (reducer, initialState) => { | |
const cachedReducer = useCallback(produce(reducer), [reducer]) | |
return useReducer(cachedReducer, initialState) | |
} | |
export default useImmerReducer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment