Created
September 6, 2023 13:51
-
-
Save arulprabakaran/33e041fa2de97e6a96c0b5569b40cf9c to your computer and use it in GitHub Desktop.
React like Hooks for Node
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
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