class 문법으로 컴포넌트 만드는 법
class Modal2 extends React.Component {
constructor(){
super();
this.state = {
name : 'kim',
age : 20
}
}
render(){
return (
<div>안녕 { this.state.name }</div>
)
}
}
class 컴포넌트에서 state 변경
class Modal2 extends React.Component {
constructor(){
super();
this.state = {
name : 'kim',
age : 20
}
}
render(){
return (
<div>안녕 { this.state.age }
<button onClick={()=>{ this.setState({age : 21}) }}>버튼</button>
</div>
)
}
}
class 컴포넌트에서 props
class Modal2 extends React.Component {
constructor(props){
super(props);
this.state = {
name : 'kim',
age : 20
}
}
render(){
return (
<div>안녕 { this.props.프롭스이름 }</div>
)
}
}