Skip to content

Align Container#setState closer to React's implementation#28

Merged
jamiebuilds merged 1 commit intomasterfrom
setState-changes
Apr 12, 2018
Merged

Align Container#setState closer to React's implementation#28
jamiebuilds merged 1 commit intomasterfrom
setState-changes

Conversation

@jamiebuilds
Copy link
Copy Markdown
Owner

This is an initial attempt at making Unstated's Container#setState work more like React's Component#setState.

setState is async

this.setState({ value: 'foo' });
this.state.value; // 'prevValue'

updater can be a function

this.setState(prevState => ({ counter: prevState.counter + 1 }));

An optional callback will run after the component's are updated

this.setState({}, () => {
  // components are updated
});

@xzilja
Copy link
Copy Markdown
Contributor

xzilja commented Apr 9, 2018

This probably addresses #1 and #27 ?

@sindresorhus
Copy link
Copy Markdown
Contributor

I've tried this PR in our app and everything seemed to work fine.

@jamiebuilds jamiebuilds merged commit 89206b3 into master Apr 12, 2018
@jamiebuilds jamiebuilds deleted the setState-changes branch April 12, 2018 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants