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

Bug: use() hook #28588

Closed
w7en opened this issue Mar 19, 2024 · 4 comments
Closed

Bug: use() hook #28588

w7en opened this issue Mar 19, 2024 · 4 comments
Labels

Comments

@w7en
Copy link

w7en commented Mar 19, 2024

React version:
"react": "0.0.0-experimental-4b84f1161-20240318",
"react-dom": "0.0.0-experimental-4b84f1161-20240318",

  1. How I can use the use() hook without Suspense component?
  2. When I use the use() hook with Suspense and call API, I see it still calls the API many times (this version: 3 times, version: 0.0.0-experimental-a870b2d54-20240314 => 4 times).

Link code example: https://github.com/bradtraversy/react-19-playground/blob/main/src/components/useExample1/Joke.jsx

@w7en w7en added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Mar 19, 2024
@albeniskerqeli10
Copy link

albeniskerqeli10 commented Mar 21, 2024

It's not because of Suspense or a bug, but the use() hook isn't cached by default, so you will see a lot of api calls when using it.

I would prefer you to go with a library like react-query to handle data fetching in React rather than using 'use' for that.

@albeniskerqeli10
Copy link

See here: https://react.dev/reference/react/use

@eps1lon eps1lon added React 19 and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Mar 21, 2024
@eps1lon
Copy link
Collaborator

eps1lon commented Mar 21, 2024

As @albeniskerqeli10 said, the promise needs to be cached. The docs don't mention that unfortunately yet which we need to fix.

@w7en
Copy link
Author

w7en commented Mar 22, 2024

Thank so much. I got it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants