Last active
May 14, 2017 10:44
-
-
Save arqex/e7ac2394971176b7b72d106bbb01a437 to your computer and use it in GitHub Desktop.
Events in Freezer
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
class UserCreator extends React.Component { | |
render(){ | |
// This component will let us create an user by name | |
return ( | |
<div className="userCreator"> | |
<input name="name" onChange={ e => this.setState({name}) } /> | |
<button onClick={ () => this.save() } /> | |
</div> | |
); | |
} | |
save(){ | |
freezer.emit( 'user:create', this.state.name ); | |
} | |
} | |
// In a different file we can handle the state update | |
// This is the `user:create reaction | |
freezer.on('user:create', name => { | |
var id = 100; | |
freezer.get().users.set(id, {id: id, name: name}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment