Skip to content

Allow function as children component in react Deferred and WhenVisible #2386

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chack1172
Copy link
Contributor

This PR aims to improve the usability of Deferred and WhenVisible components without having to create extra components to render data. Is it not possible to write jsx data directly because even though the children is not rendered, React still evalutates it and errors are thrown for accessing undefined data.

This is not possible:

<Deferred data="options" fallback={<span>Loading select...</span>}>
<select>
{options.map({label, value} => <option value={value}>{label}</option>}
</select>
</Deferred>

With the new changes we can do this, in this way react will only evalutate the children if it is actually rendered:

<Deferred data="options" fallback={<span>Loading select...</span>}>
  {() => <select>
     {options.map({label, value} => <option value={value}>{label}</option>}
  </select>
</Deferred>

Notes:

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.

1 participant