Created
June 7, 2019 04:55
-
-
Save nicksheffield/6ee6e91d59e5e6458e196e023f273beb to your computer and use it in GitHub Desktop.
Like useReducer, but doesn't trigger component renders
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 characters
| import React, { useRef, useCallback } from 'react' | |
| const useWeakReducer = (reducer, initialState) => { | |
| const ref = useRef(initialState) | |
| const dispatch = useCallback((action) => { | |
| ref.current = reducer(ref.current, action) | |
| }, []) | |
| return [ref.current, dispatch] | |
| } | |
| export default useWeakReducer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment