본문 바로가기
프로그래밍

리액트 React 삼항연산자, setTimeout, state 값 변경 알아보기

by DW.K 2020. 11. 9.

App.js

import React from "react";
import PropTypes from "prop-types";

// render() -> mount -> componentDidMount() -> 6s

class App extends React.Component {
  state = {
    isLoading: true,
    movies: []
  };
  componentDidMount() {
    setTimeout(() => {
      this.setState({isLoading : false});
    }, 6000);
  }
  render() {
    const { isLoading } = this.state;
  return <div>{this.state.isLoading ? "Loading...": "We are ready"}</div>;
  }
}


export default App;

 

댓글