如何在React Navigation功能组件中访问Redux道具

时间:2020-06-27 17:16:17

标签: reactjs react-native redux react-redux react-navigation

我正在将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)

1 个答案:

答案 0 :(得分:1)

您只需要在screen1参数中添加prop1,如下所示:

const Screen1 = ({ navigation, prop1}) => {
// ... do some stuff
const goToScreen2 = () => {
    navigation.navigate('Screen2');
}}