通过NavigatorIOS传递Redux状态

时间:2016-02-12 15:34:45

标签: ios navigation react-native redux

我正在将Redux集成到React Native应用程序中。我在解决如何通过NavigatorIOS组件传递Redux状态时遇到了麻烦。

当执行进入下面显示的组件时,调试器显示

{ extern int printf(const char * fmt, ...); printf("hello?\n"); } 使用actions对象中的预期操作,并且状态尚未定义,因为它尚未初始化(我假设)。

但是,当执行进入ItemIndex组件时,调试器会显示 props = Object {state: undefined, actions: Object}

我当前的实现尝试显式传递状态和操作,但它们没有通过:调试器现在显示 props = Object {navigator: Object, route: Object}


props = Object {navigator: Object, route: Object, state: null, actions: undefined}

有没有办法可以继续通过class MainComponent extends Component { constructor(props) { super(props) const { actions, state } = props } render() { return ( <NavigatorIOS ref = "nav" style = {styles.navigator} initialRoute = {{ // Pass redux state into component passProps: { state: this.state, actions: this.actions }, // currently becomes { state: null, actions: undefined } title: 'Items', component: ItemIndex }}/> ) } } module.exports = MainComponent 传递Redux状态?

2 个答案:

答案 0 :(得分:2)

react-native-navigation支持Redux,使用原生iOS视图控制器(通过react-native-controllers而不是navigatorIOS),并将很快支持Android。到目前为止,这是满足我需求的最佳导航解决方案。

答案 1 :(得分:0)

我意识到我要离开链条的props部分:

  render() {
    return (
      <NavigatorIOS
        ref = "nav"
        style = {styles.navigator}
        initialRoute = {{
          // Pass redux state into component
          passProps: { state: this.props.state, actions: this.props.actions },  
          title: 'Items',
          component: ItemIndex
        }}/> 
    )
  }

实际上 - 这仅适用于初始状态,它似乎停止状态更改触发initialRoute组件和后续组件的组件更新。

相关问题