setTimeout react 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);
}, []);
Example 3: settimeout react example
import React, {Component} from 'react';
import Router_App from './Router';
import "./App.css";
class App extends Component {
constructor(props){
super(props);
this.state = {
timePassed: false
};
}
render() {
setTimeout(() => {this.setState({timePassed: true})}, 1700);
if (!this.state.timePassed){
return (
<div style={{textAlign:"center",marginTop:"15%",fontSize:"5.5rem"}}>
<p>M E A N I N G <br/>O F<br/> C O D E</p>
</div>
);
}else{
return (
<Router_App/>
);
}
}
}
export default App;