Skip to content

Instantly share code, notes, and snippets.

@arulprabakaran
Created September 6, 2023 13:51
Show Gist options
  • Save arulprabakaran/33e041fa2de97e6a96c0b5569b40cf9c to your computer and use it in GitHub Desktop.
Save arulprabakaran/33e041fa2de97e6a96c0b5569b40cf9c to your computer and use it in GitHub Desktop.
React like Hooks for Node
function useState(initVal) {
let _val = initVal;
const state = () => _val;
const setState = newVal => {
_val = newVal;
}
return [state, setState];
}
// Example
const [count, setCount] = useState(1);
console.log(count());
setCount(2);
console.log(count());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment