Published 2021. 2. 23. 20:25
728x90
반응형

state활용해 5초 후에 내용 바꾸기 예제

Loading → Finish(5초 후)

import React from 'react';

class App extends React.Component{
  state = {
    isLoading: true
  };
  componentDidMount() {
    setTimeout(() => {
      this.setState({ isLoading: false });
    }, 5000);
  };
  render() {
    const { isLoading } = this.state;
    return <div>{this.state.isLoading ? "Loading" : "Finish"}</div>;
  };
}
  

export default App;
반응형

'프로그래밍 > React' 카테고리의 다른 글

react-router-dom  (0) 2021.03.03
SPA(Single Page Application)  (0) 2021.03.02
Component Life Cycle  (0) 2021.02.22
component 예제  (0) 2021.02.19
create-react-app 설치  (0) 2021.02.17
복사했습니다!