-
Use the
useState()hook to create theshownstate variable and set its value tofalse. -
When the
<button>is clicked, executesetShown, toggling thetypeof the<input>between'text'and'password'.
const PasswordRevealer = ({ value }) => {
const [shown, setShown] = React.useState(false);
return (
<>
<input type={shown ? 'text' : 'password'} value={value} />
<button onClick={() => setShown(!shown)}>Show/Hide</button>
</>
);
};