React :: 변수 선언
* 변수 선언
변수 선언 방법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>
);
}
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: '',
}
}
}
class GuGuDan extends React.Component {
state = {
x: Math.ceil(Math.random() * 9),
y: Math.ceil(Math.random() * 9),
value: '',
result: '',
}
}
render() {
return (
<React.Fragment>
<p>{this.state.x} 곱하기 {this.state.y}는?</p>
<div>{this.state.result}</div>
</React.Fragment>
);
}
cf.Zerocho
Author And Source
이 문제에 관하여(React :: 변수 선언), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@pricelesslife/React-변수-선언저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)