Skip to content

[Suggestion]: use hook missing explanations of handling promises created on the client #8290

Description

@MaxwellCohen

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:

  1. 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.

  1. An example using cached promises, similar to be shown starting at 21:37 of
    Async React conf talk by @rickhanlonii

  2. Add to the Troubleshooting section about how to deal with use Hook not showing content and reloading content.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions