【发布时间】:2016-10-13 04:29:48
【问题描述】:
我有一个在 React Native Navigator 组件中创建的 react-redux 容器组件。我希望能够将导航器作为道具传递给此容器组件,以便在其展示组件内按下按钮后,它可以将对象推送到导航器堆栈上。
我想这样做,而不需要手写 react-redux 容器组件给我的所有样板代码(也不要错过 react-redux 在这里给我的所有优化)。
示例容器组件代码:
const mapStateToProps = (state) => {
return {
prop1: state.prop1,
prop2: state.prop2
}
}
const mapDispatchToProps = (dispatch) => {
return {
onSearchPressed: (e) => {
dispatch(submitSearch(navigator)) // This is where I want to use the injected navigator
}
}
}
const SearchViewContainer = connect(
mapStateToProps,
mapDispatchToProps
)(SearchView)
export default SearchViewContainer
我希望能够从我的导航器renderScene 函数中调用这样的组件:
<SearchViewContainer navigator={navigator}/>
在上面的容器代码中,我需要能够从 mapDispatchToProps 函数中访问这个传递的道具。
我不喜欢将导航器存储在 redux 状态对象上,也不想将 prop 传递给演示组件。
有没有办法可以将道具传递给这个容器组件?或者,有没有我忽略的替代方法?
谢谢。
【问题讨论】:
标签: reactjs react-native redux react-redux