Created
June 9, 2023 12:50
-
-
Save vishnuroshan/b2828917986ee3575fe4ece84989c99a to your computer and use it in GitHub Desktop.
A very crude imagination of how useState works internally in react (definitely wrong)
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; | |
let state = () => _val; | |
const setState = (newVal) => _val = newVal; | |
return [state, setState] | |
} | |
const [c, setC] = useState(1); | |
console.log(c()); | |
setC(2); | |
console.log(c()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment