Skip to content

Instantly share code, notes, and snippets.

@devsnek
Created February 10, 2019 04:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devsnek/5b46d2bd86c953a1bc88f89612be6bc8 to your computer and use it in GitHub Desktop.
Save devsnek/5b46d2bd86c953a1bc88f89612be6bc8 to your computer and use it in GitHub Desktop.
'use strict';
const stateMap = new WeakMap();
function useState(key, init) {
const update = (v) => stateMap.set(key, v);
if (stateMap.has(key)) {
return [stateMap.get(key), update];
}
stateMap.set(key, init);
return [init, update];
}
for (let i = 0; i < 10; i += 1) {
const [count, setCount] = useState`${0}`;
console.log(count);
setCount(count + 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment