Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async render function? #10867

Closed
pie6k opened this issue Sep 27, 2017 · 6 comments
Closed

Async render function? #10867

pie6k opened this issue Sep 27, 2017 · 6 comments

Comments

@pie6k
Copy link

pie6k commented Sep 27, 2017

Since Fiber is here - did you, as React team, even consider having render functions like:

class UserInfo extends Component {
  async render() {
    const apiData = await fetchUser(this.props.userId);
    return <div>{apiData.userName}</div>;
  }
}

Obviously, it's changing some core ways about how react is working.

There are few consequences about such approach:

  • every render needs to be promise. (it'd be back-compatible tho)
  • it'd require figuring out how loading state is shown up

I imagine whole new way you could write apps that rely on async api's:

class UserInfo extends Component {
  async render() {
    const apiData = await fetchUser(this.props.userId);
    return <div className={await fetchUserType()}>{apiData.userName}</div>;
  }
}

What do you think about it?

@Jessidhia
Copy link
Contributor

Looks like a big footgun 🤔

Your component would re-download user data on every single reconciliation, and the component tree would be stuck waiting on your component to finish downloading every time.

@stephenkingsley
Copy link

I think if provide async render, you can do something fetch request abandon redux. And It will let your project store or state is messy.

@gaearon
Copy link
Collaborator

gaearon commented Oct 4, 2017

Please see #6481.

@gaearon gaearon closed this as completed Oct 4, 2017
@maxjf1
Copy link

maxjf1 commented Apr 8, 2018

Your component would re-download user data on every single reconciliation, and the component tree would be stuck waiting on your component to finish downloading every time.

@Kovensky not necessarily, this is an development choice. I could for instance cache the request if i didn't need to redownload it

@gaearon
Copy link
Collaborator

gaearon commented Apr 8, 2018

This is exactly what we’re doing with Suspense. Please see second part of my talk: https://reactjs.org/blog/2018/03/01/sneak-peek-beyond-react-16.html.

@rodinhart
Copy link

Suspense does handle this use case, but I'm looking for a value for fallback (in <Suspense) that will keep the "previous" DOM visible until all the promises have been resolve and the new tree can be rendered?

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

No branches or pull requests

6 participants