Created
October 3, 2021 00:41
-
-
Save katesroad/2c6f00c9e98e0b815000649435525ac7 to your computer and use it in GitHub Desktop.
react useReducer
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
// change can be a function or an object | |
const reduderFn = (state, change) => ({ | |
...state, | |
...(typeof change === 'function' ? change(state): action), | |
}); | |
const Counter = ({step}) => { | |
const [count, setCount] = React.useReducer(reducerFn, 0); | |
const handleIncrement = () => { | |
return setCount(curState => ({count: currentState + step})); | |
}; | |
// Jsx stuff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment