how to set timeout in javascript react code example
Example 1: settimeout in react
useEffect(() => {
const timeout = setTimeout(() => {
history.push('/dashboard');
}, 3000);
},[]);
Example 2: 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;