Last active
May 13, 2017 16:26
-
-
Save arqex/04b0727dbdb0613720376ac81bdcb0a4 to your computer and use it in GitHub Desktop.
Rerender on update
This file contains hidden or 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
// Our root component | |
class App extends React.Component { | |
constructor(){ | |
super(); | |
this.state = freezer.get(); | |
} | |
render(){ /.../ } | |
componentDidUpdate(){ | |
// Re-render on update | |
// Our UI will always synchronized with the state | |
freezer.on('update', nextState => { | |
this.setState( nextState ); | |
}); | |
} | |
} | |
// Anywhere in the app | |
// This will refresh the UI | |
freezer.get().me.set({name: 'Manuel'}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment