[React] constructor() 생성자 사용법
Node.js
2021. 10. 20. 15:38
class TempComponent extends Component{ constructor(props){ super(props); } render(){ return(); } } React에서 Component를 생성할 때 state 값을 초기화하거나 메서드를 바인딩할 때 construcotr()를 사용합니다. React의 Component의 생성자는 해당 Component가 마운트 되기 전 호출됩니다. React.Component를 상속한 컴포넌트의 생성자를 구현할 때는 super(props)를 선언을 권고하고 있습니다. 이유는 this.props 사용 시 생성자 내에서 정의되지 않아 버그 발생 가능성이 생기기 때문입니다. class TempComponent extends Component{ constr..