Skip to content

Instantly share code, notes, and snippets.

@syeo66
Created May 2, 2019 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syeo66/53e56adb335f94071f58b835523f1d99 to your computer and use it in GitHub Desktop.
Save syeo66/53e56adb335f94071f58b835523f1d99 to your computer and use it in GitHub Desktop.
Creating useState() - I'm soooooo clever
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