Skip to content

Instantly share code, notes, and snippets.

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