Last active
July 6, 2017 19:28
-
-
Save glortho/d22b377348dc79d7259ac34eb78ebcd6 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, localState } from 'jetset'; | |
/* without decorators you could do something like... | |
const usesGlobalState = globalState({ example: 'bar' }); | |
const usesLocalState = localState({ localExample: 'foo' }); | |
... | |
export default usesGlobalState( usesLocalState( CombinedStateExample ) ); | |
*/ | |
@globalState({ example: 'bar' }) | |
@localState({ localExample: 'foo' }) | |
class CombinedStateExample extends React.Component { | |
render() { | |
return ( | |
<div> | |
<div> | |
<span>local example state: { this.props.localExample.get() }</span> | |
<button onClick={() => this.props.localExample.set( 'foo' )}>Set to foo</button> | |
<button onClick={() => this.props.localExample.set( 'bar' )}>Set to bar</button> | |
</div> | |
<div> | |
<span>example2 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> | |
); | |
} | |
} | |
export default CombinedStateExample; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment