【发布时间】:2016-05-23 19:53:51
【问题描述】:
我正在将 Redux 集成到 React Native 应用程序中。我无法弄清楚如何通过 NavigatorIOS 组件传递 Redux 状态。
当执行进入下图组件时,调试器显示
props = Object {state: undefined, actions: Object}
使用操作对象中的预期操作,并且状态尚未定义,因为它尚未初始化(我假设)。
但是当执行进入 ItemIndex 组件时,调试器显示
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
有没有办法让我继续通过 NavigatorIOS 传递 Redux 状态?
【问题讨论】:
-
将它们作为props 注入到initialRoute 怎么样?我知道这可能与您的应用程序的结构不符,但这是一种方式。
-
@NaderDabit 你能举个例子吗?
标签: ios navigation react-native redux