facebook/react

Bug: use() hook

w7en opened this issue ยท 4 comments

w7en commented

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

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.

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

w7en commented

Thank so much. I got it