What is the best way to set the required attribute based on a state in React?

I’d like to set the required attribute on input based on a state, I tried something like the following:

const [required, setRequired] = useState(false)

return(
  <form onSubmit={submitHandler}>
    <input id='name' type='text' required={required} onChange={changeHandler} />
  </form>
)

At the moment, I can’t submit the form as the input is still required ‘even if my state is false’. What am I missing?
Thanks in advance!