Last active
July 15, 2020 01:40
-
-
Save brennop/a136865482e0e70f2911482e77cab1b1 to your computer and use it in GitHub Desktop.
useReducer but it's actually useState (which it's actually useReducer)
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 { useState } from "react"; | |
function useReducer(reducer, initialState) { | |
const [state, setState] = useState(initialState); | |
const dispatch = action => { | |
setState(reducer(state, action)); | |
}; | |
return [state, dispatch]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment