아래 코드에서 누군가가 함수에 저장된 액세스 방법에 대해 조언 할 수 있습니까? 자식 QRScan
구성 요소로 전달되는 보조물 closeModal
?하위 구성 요소의 함수에서 호출 할 수 있도록 소품을 통해 하위 구성 요소에 전달 된 함수에 바인딩하는 방법
나는 QRScan
의 생성자에서 this.props.closeModal.bind(this)
을 시도했지만 나는 _onBarCodeRead
기능에 this.props.closeModal()
를 호출 할 때 나는 undefined is not an object (evaluating 'this.props.closedModal')
오류가 발생합니다.
소품이 확실히 생성자로 전달되는 중입니다. 함수를 올바르게 바인딩 할 수 없습니다. 도움이 많이 감사!
class Test extends React.Component {
constructor(props) {
super(props);
}
_test(){
console.log("test worked")
}
render() {
return (
<View>
<QRScan closeModal={this._test}/>
</View>
}
}
아이 클래스 : 현재 위치에서 기능을 수정하지 않는 함수를 바인딩
class QRScan extends React.Component {
constructor(props)
{
super(props)
console.log(this.props)
this.props.closeModal.bind(this);
}
render() {
return (
<BarcodeScanner
onBarCodeRead={this._onBarCodeRead}
width={windowWidth}
height={windowWidth * cameraAspectRatio}
style={styles.camera}>
<View style={styles.rectangleContainer}>
<View style={styles.rectangle} />
</View>
</BarcodeScanner>
);
}
_onBarCodeRead(e) {
console.log(e);
Vibration.vibrate();
this.props.closeModal();
}
}
다음을 추가 할 필요가! –