Skip to content

Instantly share code, notes, and snippets.

@miladvafaeifard
Created February 9, 2019 22:46
Show Gist options
  • Save miladvafaeifard/43dc710115e0cfab59136d1c96074a30 to your computer and use it in GitHub Desktop.
Save miladvafaeifard/43dc710115e0cfab59136d1c96074a30 to your computer and use it in GitHub Desktop.
a part of react-setState-like functionality only for count function
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