子コンポーネント内の親コンポーネントにある関数を呼び出そうとしていますが、ワーキング。React Native:子コンポーネントの親コンポーネントの関数を呼び出す際に問題が発生しました。
今私は現在、このエラーを取得しています: E ReactNativeJS: { [TypeError: undefined is not a function (evaluating '_this.props.setModalVisible(false)')]
私はSO上で同様の質問を見てきましたが、それを把握することはできません。どんな助けでも大歓迎です!
私の親コンポーネントのコード:
constructor (props) {
super(props)
this.setModalVisible = this.setModalVisible.bind(this)
this.state = {
modalVisible: false,
}
}
setModalVisible = (visible) => {
this.setState({modalVisible: visible});
}
...
return <Child setModalVisible={ this.setModalVisible } />;
私の子コンポーネントのコード:
handlePress = (setModalVisible) => {
this.lookUp(setModalVisible);
}
lookUp = (setModalVisible) => {
fetch('https://example.com/path/that/works')
.then((response) => {
if(response.ok) {
// TRYING TO MAKE THIS WORK
this.props.setModalVisible(false)
}
})
...
}
render() {
const { setModalVisible } = this.props
return (
<Button onPress={() => this.handlePress(this.props.setModalVisible) }>View Thing</Button>
)
}
Hrmでもエラーが発生します: '[TypeError:undefinedは関数ではありません( '_this2.setModalVisible(val)'を評価しています)]'私は、見てください:https://gist.github.com/chapeljuice/ea57a25f6e8366527a6bae78f3c9d98c – chapeljuice
エラーを見つけるのは難しいですが、どのラインまたはエラーポイントを置くことができます –
はいもちろん、それはchild.jsの行69です要点 – chapeljuice