정기적으로 업데이트되는 구성 요소가 있는데이 구성 요소 외부에서 유틸리티 함수를 작성하려고합니다. 구성 요소가 업데이트 될 때 내부 상태를 업데이트해야합니다. 예를 들어React 구성 요소가 업데이트되었는지 확인하는 방법은 무엇입니까?
: 나는 Sample
기능에 Utility
기능을 통과해야한다면 나는이 달성 될 수있어
class Sample extends React.Component {
constructor(props) {
super(props);
this.state = { counter: 1 };
}
}
class Utility {
constructor(componentInstance) {
this.internalNum = // computedInstance's internal counter state (how?)
// and when the component has updated, I'd like to change the internalNum (how?)
}
}
은 Sample
Utility
업데이트의 반작용 수명주기 방법을 기반으로,하지만 난 싶지 않아 그 종류의 종속성을 Sample
에 소개합니다.
아마도 여기에는 더 좋은 디자인 패턴이 있습니다. 또는 이것이 괜찮 으면 어떻게 작동할까요?
'샘플'의 여러 인스턴스를 렌더링하면 어떻게됩니까? –