settimeout t react code example

Example 1: react timeout function

useEffect(() => {
  const timer = setTimeout(() => {
    console.log('This will run after 1 second!')
  }, 1000);
  return () => clearTimeout(timer);
}, []);

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;