구성 요소 생성자가 둘 이상의 매개 변수를 가질 수 있는지 궁금하십니까?
에서:
constructor(props) {
super(props)
}
으로:
constructor(props, parent) {
super(props)
this.parent = parent;
}
따라서 부모는 this.parent
자식 구성 요소 내부에 할당 할 수 있습니다 .
예를 들어 다음은 자식을 초기화하려는 부모 구성 요소입니다.
constructor(props) {
super(props)
this.helpers = new Child(<i_am_not_sure_here>, this);
}
일반적으로 React에서 생성자는 두 가지 목적으로 만 사용됩니다.
자세한 내용은 공식 문서를 확인하세요.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다