settimeout with states react code example
Example 1: settimeout in react
useEffect(() => {
const timeout = setTimeout(() => {
history.push('/dashboard');
}, 3000);
},[]);
Example 2: react timeout function
useEffect(() => {
const timer = setTimeout(() => {
console.log('This will run after 1 second!')
}, 1000);
return () => clearTimeout(timer);
}, []);