useId spews out identical ids
See original GitHub issuepreact 10.11.2
preact-compat 3.19.0
const C1 = () => {
const id = useId();
return <h2> {id} </h2>;
};
const App = () => {
return (
<>
<h1> TEST </h1>
<div>
<C1 />
</div>
<div>
<C1 />
</div>
</>
);
};
https://codesandbox.io/s/friendly-moon-9xlcfs?file=/src/index.js
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
JQuery to check for duplicate ids in a DOM - Stack Overflow
I like this because it spits out the actual elements to the console. ... following " + duplicates.length + " ids are used...
Read more >useId Hook Explained - Web Dev Simplified Blog
The main use case of the useId hook is to generate unique ids for ... be to create an id for an input...
Read more >React 18 provides useId API for generating unique IDs on ...
React 18 introduces a new hook API - useId, that generates stable ids during server rendering and hydration to avoid mismatches.
Read more >useId - React Docs
useId is a React Hook for generating unique IDs that can be passed to ... useId requires an identical component tree on the...
Read more >Acetaminophen (Tylenol®) - Nationwide Children's Hospital
Acetaminophen is used to reduce fever and treat pain. ... If your child gags or chokes and spits out the dose before swallowing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve found yet another suspicious thing about preact’s implementation of
useId()
Consider the following code
https://codesandbox.io/s/fervent-hopper-33n4ul?file=/src/index.js
On top of the previous problem, when I press the button, which causes C1 to be replaced with C2, the id stays the same. This can lead to all sorts of problems. It is also inconsistent with the reference implementation of react.
https://codesandbox.io/s/zen-volhard-lfkryj?file=/src/App.js
Another potential issue:
results in:
See: https://codesandbox.io/s/preact-useid-multiple-y0qbwq?file=/src/index.js