React component는 Class 형식으로도 사용할 수 있다. (최신 버전에서는 function 형태를 권장한다고 함)
class ClassName extends Component {
// constructor와 constructor 내 super() 호출, render()는 필수
constructor(props) { // props를 선언
super(props);
this.state = { // state 선언. let [state1] = useState(...)
state1 : ...,
state2 : ...
}
}
render() {
return (
...
... this.setState({ state1 : ... }); // state 변경 setState(...)
)
}
}
'개발 > React 학습' 카테고리의 다른 글
외부 리소스 참조하기 (0) | 2023.03.08 |
---|---|
React Bootstrap 사용 (0) | 2023.03.08 |
글쓰기1 (0) | 2023.03.06 |
props (0) | 2023.03.06 |
MAP() (0) | 2023.03.02 |