Skip to content

Commit

Permalink
add useId
Browse files Browse the repository at this point in the history
  • Loading branch information
beumsk committed Oct 31, 2024
1 parent 2824575 commit 0e19eeb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions React.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,33 @@ const ChildComponent = () => {



// ID HOOK
// very useful to have unique IDs generated for similar elements
import { useId } from 'react';

function PasswordField() {
const passwordHintId = useId();
return (
<>
<label>
Password:
<input type="password" aria-describedby={passwordHintId} />
</label>
<p id={passwordHintId}>The password should contain at least 18 characters</p>
</>
);
}

export default function App() {
return (
<>
<h2>Choose password</h2>
<PasswordField />
<h2>Confirm password</h2>
<PasswordField />
</>
);
}



Expand Down

0 comments on commit 0e19eeb

Please sign in to comment.