Skip to content

Instantly share code, notes, and snippets.

@glortho
Last active July 6, 2017 19:28
Show Gist options
  • Save glortho/d22b377348dc79d7259ac34eb78ebcd6 to your computer and use it in GitHub Desktop.
Save glortho/d22b377348dc79d7259ac34eb78ebcd6 to your computer and use it in GitHub Desktop.
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