Promise-returning setState and forceUpdate by thejameskyle · Pull Request #10 · reactjs/rfcs · GitHub

  • Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
  • Already on GitHub?
  • Sign in to your account

rfcs – RFCs for changes to React

We recommend upgrading to the latest Safari, Google Chrome, or Firefox.

The vote is over, but the fight for net neutrality isn’t. Show your support for a free and open internet.

GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.

class DataFetcher extends React.Component { state = { loading: false, error: null, data: null, }; async componentDidMount() { await this.setState({ loading: true }); try { let response = await fetch(this.props.url); let data = await response.json(); await this.setState({ data, loading: false }); } catch (error) { await this.setState({ error, loading: false }); } }; render() { return this.props.render(this.state); } }

being applied before continuing. I can come up with a better example if people want it better demonstrated. I figured the data fetching example was easiest to understand.

This commit was created on GitHub.com and signed with a verified signature using GitHub’s key.

+- If `setState` without the callback is (or could be) optimized in anyway (due to not

+ needing the schedule the callback or something), it wouldn’t be able to anymore because

+ the promise would always have to be returned.

“Yes, we’d have to tag it as a node to visit when committing changes. setState() without callback doesn’t need that.” – Dan

Depending on how big of an impact this makes, I…

Promise-returning setState and forceUpdate by thejameskyle · Pull Request #10 · reactjs/rfcs · GitHub