Last active
July 6, 2017 19:27
-
-
Save glortho/96db2c77ab0bc1b345944fd3e8ab8501 to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
import { globalState } from 'jetset'; | |
@globalState({ example: 'foo', example2: 'bar' }, 'exampleWithNoInitialState') | |
class GlobalStateExample extends React.Component { | |
render() { | |
return ( | |
<div> | |
<div> | |
<span>example state: { this.props.example.get() }</span> | |
<button onClick={() => this.props.example.set( 'foo' )}>Set to foo</button> | |
<button onClick={() => this.props.example.set( 'bar' )}>Set to bar</button> | |
</div> | |
<div> | |
<span>example2 state: { this.props.example2.get() }</span> | |
<button onClick={() => this.props.example2.set( 'foo' )}>Set to foo</button> | |
<button onClick={() => this.props.example2.set( 'bar' )}>Set to bar</button> | |
</div> | |
<div> | |
<span>exampleWithNoInitialState: { this.props.exampleWithNoInitialState.get() || 'n/a'}</span> | |
<button onClick={() => this.props.exampleWithNoInitialState.set( 'foo' )}>Set to foo</button> | |
<button onClick={() => this.props.exampleWithNoInitialState.set( 'bar' )}>Set to bar</button> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default GlobalStateExample; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment