Skip to content

Conversation

@jamiebuilds
Copy link
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
Contributor

xzilja commented Apr 9, 2018

This probably addresses #1 and #27 ?

@sindresorhus
Copy link
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.

4 participants