Browse Source

Document useId is not for keys (#4557)

main
dan 3 years ago
committed by GitHub
parent
commit
65b04292eb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      content/blog/2022-03-29-react-v18.md
  2. 4
      content/docs/hooks-reference.md

4
content/blog/2022-03-29-react-v18.md

@ -220,6 +220,10 @@ With Strict Mode in React 18, React will simulate unmounting and remounting the
`useId` is a new hook for generating unique IDs on both the client and server, while avoiding hydration mismatches. It is primarily useful for component libraries integrating with accessibility APIs that require unique IDs. This solves an issue that already exists in React 17 and below, but it's even more important in React 18 because of how the new streaming server renderer delivers HTML out-of-order. [See docs here](/docs/hooks-reference.html#useid).
> Note
>
> `useId` is **not** for generating [keys in a list](/docs/lists-and-keys.html#keys). Keys should be generated from your data.
#### useTransition {#usetransition}
`useTransition` and `startTransition` let you mark some state updates as not urgent. Other state updates are considered urgent by default. React will allow urgent state updates (for example, updating a text input) to interrupt non-urgent state updates (for example, rendering a list of search results). [See docs here](/docs/hooks-reference.html#usetransition)

4
content/docs/hooks-reference.md

@ -611,6 +611,10 @@ const id = useId();
`useId` is a hook for generating unique IDs that are stable across the server and client, while avoiding hydration mismatches.
> Note
>
> `useId` is **not** for generating [keys in a list](/docs/lists-and-keys.html#keys). Keys should be generated from your data.
For a basic example, pass the `id` directly to the elements that need it:
```js

Loading…
Cancel
Save