gpt4 book ai didi

reactjs - 通过在内部调用 navigation.navigate() 来制作共享组件 - React Native

转载 作者:行者123 更新时间:2023-12-03 14:09:06 25 4
gpt4 key购买 nike

我想在 native react 中为所有屏幕制作共享组件。这样我就可以在主要组件之间共享它们。

enter image description here

请参阅下面的代码,一切正常,但 this.props.navigation.navigation.navigate('HireJob') 不起作用。

我的代码:

export default class MyComponent extends Component {

callAndPush = () =>{
console.log('callAndPush');
this.props.navigation.navigate('HireJob')
}

render() {
return (
<TouchableHighlight style = {{backgroundColor : 'red' , height : 30}} onPress = {() => this.callAndPush()}>
<Text>Apple</Text>
</TouchableHighlight>
);
}
}

组件的使用:

 render(){
return (
<View style = {styles.scrollSty}>
<MyComponent></MyComponent>
</View>
);
}
}

最佳答案

它的工作原理如下,绕过navigation prop进入MyComponent

<MyComponent {...this.props} />

关于reactjs - 通过在内部调用 navigation.navigate() 来制作共享组件 - React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45560822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com