Skip to content

Instantly share code, notes, and snippets.

@quisido
Created April 21, 2019 20:31
Show Gist options
  • Save quisido/cd7f2abe6f8f642bc5d073df832a4860 to your computer and use it in GitHub Desktop.
Save quisido/cd7f2abe6f8f642bc5d073df832a4860 to your computer and use it in GitHub Desktop.
ReactN: addCallback Example
import { addCallback, setGlobal } from 'reactn';
// Every time the global state changes, this function will execute.
function prevent1(newGlobalState) {
alert(`The new value is ${newGlobalState.value}!`);
// If the global state was changed to 1, change it to 2.
if (newGlobalState.value === 1) {
return { value: 2 };
}
}
addCallback(prevent1);
setGlobal({ value: 1 });
// The new value is 1!
// The new value is 2!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment