React’s “use” hook in 1 tweet: Works like “await”


React’s “use” hook in 1 tweet:

Works like “await”.
Wraps promises (and soon other things).
The component replays when the promise resolves.
Only for client.
Can be called conditionally!
Can be placed in the same spots as “await”.
Part of Suspense data fetching story.

#react

More info in the full RFC: https://github.com/reactjs/rfcs/pull/229
Many good questions about “use” in this thread.

Q: Won’t this create a new promise on each render?
A: Yes, but the “cache” hook will resolve that.

Q: How errors handled?
A: They bubble to the nearest ErrorBoundary.

Q: What about loading UI?
A: Wrap via Suspense with fallback.

View original on X