I want to show alert
that message was sent (202) or has errors (else) on screen but this message should be clean after 3 seconds.
I usually use it only in useEffect
hook, but I want it put in a condition
if (res.status === 200) {
setTimeout(function() {
setStatus('success')
}, 1000);
Update:
I tried suggested snippets of code, but not working. Solution with [res...]
cause a error, because react do not see variable like that. I go forward with this code, adding in if statement new variable which is associated with res... but still not work
useEffect(() => {
const timer = ""
if (kupa === "sukces") {
const timer = setTimeout(function() {
setStatus('success') }, 1000);
}
if (kupa === "error") {
const timer = setTimeout(function() {
setStatus('error') }, 1000);
}
return () => clearTimeout(timer);
}, [kupa]);