Reputation: 15
I have this function.
const handleSubmit = async () => {
event.preventDefault();
setLoading(true);
try {
await axios.get('/something');
} catch {
setLoading(false);
};
};
And I want to setLoad onClick. However, doing that I also rerender the page, and I lost all my form data. Putting inside the try will not cause the expected effect.
Tried with useRef, but that doesn't make the form data disappear but neither the loading appear, 'cause again: the page doesn't rerender.
Any solution?
Upvotes: 0
Views: 302
Reputation: 11
You forgot to put event
as function parameter
const handleSubmit = async (event) => {
event.preventDefault();
setLoading(true);
try {
await axios.get('/something');
} catch {
setLoading(false);
};
};
Upvotes: 1