Skip to content

Instantly share code, notes, and snippets.

@orYoffe
Last active July 23, 2020 15:29
Show Gist options
  • Save orYoffe/25fe1747deb524737bb301d7d2c63ded to your computer and use it in GitHub Desktop.
Save orYoffe/25fe1747deb524737bb301d7d2c63ded to your computer and use it in GitHub Desktop.
jstates simple example
const createState = require("jstates");
const myState = createState({ counter: 0 });
function onUpdate(state) {
console.log("onUpdate: counter =", state.counter);
}
myState.subscribe(onUpdate);
myState.setState(state => ({ counter: ++state.counter }));
// => onUpdate: counter = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment