我正在将Redux添加到我的React Native项目中,并面临以下问题。
有一个屏幕 Screen1 :
const Screen1 = ({ navigation }) => {
// ... do some stuff
const goToScreen2 = () => {
navigation.navigate('Screen2');
}
// how to access prop1 here???
}
const mapStateToProps = (state) => {
return {
prop1: state.myDesireProp
}
}
export default connect(mapStateToProps)(Screen1)
答案 0 :(得分:1)
您只需要在screen1参数中添加prop1,如下所示:
const Screen1 = ({ navigation, prop1}) => {
// ... do some stuff
const goToScreen2 = () => {
navigation.navigate('Screen2');
}}