React State Handling

2021. 7. 24. 15:34React

React에서 state을 변경할 때는 setState를 이용해야

rendering됨

 

componentDidMount() {

    setTimeout(() => {

        this.state.count = this.state.count + 1;

        }, 1000);

}

동작X

 

componentDidMount() {

    setTimeout(() => {

        this.setState({

            count: this.state.count + 1;

        });

    }, 1000);

}

동작O