Created
April 21, 2019 20:31
-
-
Save quisido/cd7f2abe6f8f642bc5d073df832a4860 to your computer and use it in GitHub Desktop.
ReactN: addCallback Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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