How to use {useID} in React18?

How to use {useID} in React18?

The useId() hook is a new way to generate a unique random Id in React 18.

The useId is a new hook introduced in React 18. The useId hook helps generate a unique Id on both the client-side and server-side.

The previous one was called the useOpaqueIdentifierhook in React. The useOpaqueIdentifierhook had many bugs and limitations, so the useId hook was delayed.

In React 18, all the issues were resolved correctly, and the React team introduced the useOpaqueIdentifierhook with the new name used.

Example :

const email = useId();

<label htmlFor={email }>Email</label>
<input id={email} />

It will generate a unique id to the code.