JSFiddle - React, Tailwind, and code Playground
HTML
<form>
<input id=a>
<input type=submit>
</form>
<button id=1>Set
<button id=2>Remove
JavaScript
a = document.getElementById('a');
document.getElementById('1').onclick = function(){
a.setAttribute('required', 'required');
}
document.getElementById('2').onclick = function(){
a.removeAttribute('required');
}