我有一个react-redux容器组件,它是在react-Native Navigator组件中创建的.我希望能够将导航器作为一个props 传递给这个容器组件,这样在其呈现组件中按下一个按钮后,它就可以将一个对象推到导航器堆栈上.
我想这样做,而不需要手工编写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
我希望能够从navigator renderScene
函数中调用如下组件:
<SearchViewContainer navigator={navigator}/>
在上面的容器代码中,我需要能够从mapDispatchToProps
函数中访问这个已传递的props .
我不喜欢将导航器存储在redux state对象上,也不想将props 传递给presentational组件.
有没有办法把props 传给这个容器组件?或者,有没有我忽略的替代方法?
谢谢