페이스북에서 제공한 ui 라이브러리
//1. functional Component
function Greeting (props){
return (<div>Hello {props.name}</div>);
}
//2. class Component
class Greeting extends React.Component{
render () {
return (<div>Hello {this.props.name}</div>);
}
}
//컴포넌트 사용하기
class App extends React.Component {
render () {
return (<Greeting name="Hello"/>);
}
}
//기본값 설정(클래스 컴포넌트 선언 후)
Greeting.defaultProps = { key : value };
//Type 검증
Greeting.propTypes ={
prop_name : PropTypes.자료형 //[.isrequired]
}
class Counter extends React.Component{
constructor(props){
super(props);
this.state = {
count : 0
};
this.plus=this.plus.bind(this);
this.minus = this. minus.bind(this);
}
render (){
return (
<div>
<h2>{this.state.count}</h2>
<button onClick={this.plus}>+</button>
<button onClick={this.minus}>-</button>
</div>
);
}
plus () {
this.setState({
count : this.state.count + 1
});
}
minus () {
this.setState({
count : this.state.count -1
});
}
}