Class Component
import React from 'react'
interface SampleProps {
required?: boolean
text : string
}
interface SampleState {
count : number
isLimited ?: boolean
}
class SampleComponent extends React.Component<SampleProps, SampleState> {
private constructor(props : SampleProps) {
super(props)
this.state = {
count : 0
isLimited : false
}
private handleClick = () => {
const newValue = this.state.count + 1
this.setState({ count : newValue, isLimited : newValue >= 10})
}
public render() {
const {
props : { required, text }
state: { count, isLimited }
} = this
return (
<div>
Sample COmponent
<div>{required ? '필수' : '필수 아님'}</div>
<div>문자 : {text}</div>
<div>count : {count}</div>
<button onClick={this.handleClick} disabled={isLimited}>
증가
</button>
</div>
)
}
}리액트 생명주기(Life Cycle)

생명주기 메서드 실행시점
ErrorBoundray
React.Component vs React.PureComponent
클래스 컴포넌트의 한계
Last updated