3.4.1 클래스형 컴포넌트의 state 공부 중인데, 코드를 그대로 쓴거 같은데, 아래와 같이 개발자 콘솔에서 오류가 뜨고 화면에는 아무것도 뜨지 않습니다.
Uncaught TypeError: Cannot destructure property 'number' of 'this.state' as it is null.
`
import React from 'react'
import { Component } from 'react'
class Counter extends Component {
constructor(props) {
super(props);
// state의 초기값 설정하기
this.teate = {
number : 0
};
}
render() {
const { number } = this.state; // state를 조회할 때는 this.state으로 조회합니다.
return (
<div>
<h1>{ number }</h1>
<button
// onClick을 통해 버튼이 클릭 되었을 때 호출할 함수를 지정합니다.
onClick={() => {
//this.setStaㄴte를 사용하여 state에 새로운 값을 넣을 수 있습니다.
this.setState ({ number: number + 1});
}}
>
+1
</button>
</div>
)
}
3.4.1 클래스형 컴포넌트의 state 공부 중인데, 코드를 그대로 쓴거 같은데, 아래와 같이 개발자 콘솔에서 오류가 뜨고 화면에는 아무것도 뜨지 않습니다.
Uncaught TypeError: Cannot destructure property 'number' of 'this.state' as it is null.
` import React from 'react' import { Component } from 'react'
class Counter extends Component { constructor(props) { super(props); // state의 초기값 설정하기 this.teate = { number : 0 }; }
}
export default Counter; `