So I've got a form which sends formData to api, goes like this:
const [state, setState] = useState(true)
const handleSubmit = async e => {
const destination = state ? true : false
// Sends FormData to api
}
return (
<form onSumbit={handleSubmit}>
<div>
<button onClick={() => setState(prev => !prev)}>click</button
<button onClick={() => setState(prev => !prev)}>click</button
</div>
// some more inputs here
<input type="submit" value="Upload" />
</form>
Every time state changes it tries to submit again. It does that only for the state used in submitHandler to calculate destination. I also tried moving destination outside of submitHandler but the result is the same.