I need help with clearing out a form input when the form has been submitted. When I submit the form, the information that I put in stays there, is there a way I can clear this out? Thanks so much for taking time out of your day to help me. Here is the code
const [data, setData] = useState(null);
function getData(e) {
setData(e.target.value);
}
function handleSubmit(e) {
e.preventDefault();
}
//function that grabs user input and insert into function
const inputValue = () => {
var userSet = data.split("");
getRandom(userSet);
};
return (
<div>
<h1>LIA</h1>
<Chalkboard />
<h1>Letter set: {data}</h1>
<form onSubmit={handleSubmit}>
<input onChange={getData} className="inputField" type="text" placeholder="Enter letters" />
<button onClick={inputValue} value="Start">
Start
</button>
</form>
</div>
);
};
export default IntervalFunction;
First of all, you should have a value property on your input field. This property in this case should contain the data variable. So, this way, on the handleSubmit method, you can call setData(null) or setData("") so as to reset the content of the input field.