Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active December 4, 2020 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save WebReflection/2494b015abe7826299ebedf31045a3e1 to your computer and use it in GitHub Desktop.
Save WebReflection/2494b015abe7826299ebedf31045a3e1 to your computer and use it in GitHub Desktop.
const augment = callback => () => {
const useState = {
init: true,
value: void 0,
update(value) {
// what should this method do?
}
};
const hooks = {
useState(value) {
if (useState.init) {
useState.init = false;
useState.value = value;
}
return [useState.value, useState.update];
}
};
callback(hooks);
};
const counter = augment(({useState}) => {
const [i, update] = useState(0);
console.log(i);
setTimeout(update, 1000, i + 1);
});
// once invoked, it should log the `i` from 0 to N
// each second the `i` should be incremented + 1
counter();
// 0
// 1
// 2
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment