Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
collardeau committed Apr 3, 2018
1 parent 99ea811 commit cf12973
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ const deriveState = [
];

class App extends React.Component<any, any> {
// init a store function
store = staterize(state, deriveState, st => {
// callback when state changes
this.setState(st);
});

state = this.store(); // no params gets current state from store
constructor() {
// init a store
this.store = staterize(state, deriveState, st => {
// callback when store state changes
this.setState(st);
});
this.state = this.store(); // get current state
}

incr() {
// now use store to make state changes
Expand All @@ -49,7 +51,7 @@ class App extends React.Component<any, any> {
<div>
{count}
isBinary: {isBinary ? 'yes' : 'no'}
<button onClick={this.incr} />
<button onClick={this.incr}>+1</button>
</div>
);
}
Expand Down

0 comments on commit cf12973

Please sign in to comment.