-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Summary
The use Hook documentation lacks caveats, examples, or troubleshooting for using the use Hook with a promise created on the client.
Page
https://react.dev/reference/react/use
Details
The current documentation for the use hook does not show how to use the use for client-created promises. When using the use Hook promsies need to be needs to be cached. This is not explicitly stated in the documentation, but it is implied by the "stable" promises. When not using a stable or cached promise, an infinite loop occurs, preventing the component from loading.
Adding the following information could help:
- Adding to the caveats section a caveat like:
A Promise used in Client Components use hooks must be cached or stable between renders (e.g., not recreated each time the use hook is called); otherwise, each render will cause the component to use the new Promise, not the previous promise, and the component may suspend indefinitely.
-
An example using cached promises, similar to be shown starting at 21:37 of
Async React conf talk by @rickhanlonii -
Add to the Troubleshooting section about how to deal with
useHook not showing content and reloading content.