Add caveat to useId for cache keys (#8242)

This commit is contained in:
Ricky
2026-01-16 13:27:58 -05:00
committed by GitHub
parent 2da4f7fbd9
commit a1ddcf51a0

View File

@@ -44,6 +44,8 @@ function PasswordField() {
* `useId` is a Hook, so you can only call it **at the top level of your component** or your own Hooks. You can't call it inside loops or conditions. If you need that, extract a new component and move the state into it.
* `useId` **should not be used to generate cache keys** for [use()](/reference/react/use). The ID is stable when a component is mounted but may change during rendering. Cache keys should be generated from your data.
* `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).