React :: 변수 선언

Tuhyon😀·2021년 2월 13일
0

React

목록 보기
2/3

* 변수 선언

변수 선언 방법1) 생성자

class GuGuDan extends React.Component { 
	constructor(props) {
		super(props);
		this.state = {
			x: Math.ceil(Math.random() * 9),
			y: Math.ceil(Math.random() * 9),
			value: '',
			result: '',
		}
	}
}

변수 선언 방법2) Object

class GuGuDan extends React.Component { 
	state = {
		x: Math.ceil(Math.random() * 9),
		y: Math.ceil(Math.random() * 9),
		value: '',
		result: '',
	}
}

* 변수 HTML 적용

render() {
	return (
		<React.Fragment>
			<p>{this.state.x} 곱하기 {this.state.y}는?</p>
			<div>{this.state.result}</div>
		</React.Fragment>
	);
}

cf.Zerocho

profile
메모를 하기 위한 공간입니다.

0개의 댓글