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

Use componentDidCatch@react16 to render Card & Spin loading #11795

Closed
1 task done
dancerphil opened this issue Aug 20, 2018 · 1 comment
Closed
1 task done

Use componentDidCatch@react16 to render Card & Spin loading #11795

dancerphil opened this issue Aug 20, 2018 · 1 comment
Assignees

Comments

@dancerphil
Copy link
Contributor

dancerphil commented Aug 20, 2018

  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

We can change

const { loading, data } = this.props;
return (
  <Card loading={loading} >
    {data && <DisplayComponent data={data} />}
  </Card>
);

to

// render loading when data is a promise & render DisplayComponent when data is fulfilled
const { data } = this.props;
return (
  <Card>
    <DisplayComponent data={data} />
  </Card>
);

They are not equivalent, and the new implement need data to be a promise to work.

So we can catch data as if (typeof data.then === 'function) { await data; }'

It may be more obvious if react release its Suspense

I think it is a later feature, but worth discussing.

What does the proposed API look like?

componentDidCatch

demo@otakustay

demo@react

@zombieJ
Copy link
Member

zombieJ commented Aug 20, 2018

Thanks for your advice.
Since consider of compatibility with react (15.x or 16.x which not support suspense), we will not include the suspense feature until old version of react not support yet.

@zombieJ zombieJ closed this as completed Aug 20, 2018
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

2 participants