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

Add note about useId being allowed in non-async Server Components #7715

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/content/reference/react/useId.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ function PasswordField() {

* `useId` **should not be used to generate keys** in a list. [Keys should be generated from your data.](/learn/rendering-lists#where-to-get-your-key)

* `useId` currently cannot be used in [async Server Components](/reference/rsc/server-components#async-components-with-server-components).
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, I thought about wording it to highlight that useId is the only hook allowed in Server Components. But then I realized this wording assumes that hooks are disallowed in Server Components. Somehow I thought this was just another React Hooks Rule, or another Server Components rule, when actually that’s not exactly the case. I think this assumption is common among devs, maybe because all of them are not allowed in SCs (except from useId which it wasn't even documented).

My main concern is that if React later introduces more hooks usable in both Server and Client Components, explaining “some hooks are allowed on server components, others aren't” might get tricky.

I can't think of a clear solution, but perhaps labeling hooks differently could help clarify this distinction. For example, “Interactive Hooks” vs. “Non-Interactive Hooks” (or simply “Hooks”).


---

## Usage {/*usage*/}
Expand Down