Created
February 9, 2019 22:46
-
-
Save miladvafaeifard/43dc710115e0cfab59136d1c96074a30 to your computer and use it in GitHub Desktop.
a part of react-setState-like functionality only for count function
This file contains hidden or 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 setState = x => { | |
let _x = x; | |
return [ | |
_x, | |
(newX) => { | |
_x += newX; | |
return _x; | |
} | |
]; | |
} | |
let [count, setCount] = setState(0); | |
setCount(count + 1); | |
setCount(count + 1); | |
setCount(count + 1); | |
console.log('count: ', setCount(count + 1)); // should output => count: 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment