【问题标题】:How to access Redux props within React Navigation functional component如何在 React Navigation 功能组件中访问 Redux 道具
【发布时间】:2020-10-18 03:28:27
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2019-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-26
      • 1970-01-01
      • 2020-06-17
      • 2020-03-31
      相关资源
      最近更新 更多