가이드를 보며 간단한것 구현해보고 알게 된것 기록해 둔다.
class Square extends React.Component {
constructor(props) { //생성자 추가
super(props);
//모든 React 컴포넌트 클래스는 생성자를 가질 때
//super(props) 호출 구문부터 작성해야 한다.
this.state = {
value: null, //state 초기화
};
}
render() {
return (
<button
className="square"
onClick={() => this.setState({value: 'X'})}
>
{this.state.value}
</button>
);
}
}
이런식으로 component 클래스를 만든다.. 이 클래스는 태그 형태로 사용가능하다
이런식으로..
class Board extends React.Component {
renderSquare(i) {
return <Square value={i} />;
}