I want to add a class to my input only when the component is updated, not when it is mounted. So, every time when I will start to write in the input, I want to add the class: demo
.
const App = () => {
function Change(e) {
setState(e.target.value);
}
useEffect(() => {
document.getElementById('test').classList.add("demo")
}, []);
const [state, setState] = useState(0);
return (
<div className="main">\sd
<input id='test' onChange={Change} type="text"/>
<p>{state}</p>
</div>
);
}
export default App;
How to do this using my code?