Created
May 2, 2019 09:34
-
-
Save syeo66/53e56adb335f94071f58b835523f1d99 to your computer and use it in GitHub Desktop.
Creating useState() - I'm soooooo clever
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 useState = (initValue) => { | |
let state = initValue; | |
const setState = (newState) => { | |
if (typeof newState === 'function') { | |
state = newState(state); | |
return; | |
} | |
state = newState; | |
} | |
return [state, setState] | |
} | |
const [myState, setMyState] = useState('test'); | |
setMyState('test2') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment