我有一個在React Native Navigator組件中創建的react-redux容器組件。我希望能夠將導航器作爲道具傳遞給此容器組件,以便在其演示組件內按下按鈕後,它可以將對象壓入導航器堆棧。將道具傳遞給react-redux容器組件
我想要這樣做,而不需要手工編寫react-redux容器組件給我的所有樣板代碼(並且也不會錯過所有反應的優化 - 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
函數中訪問通過的prop。
我不喜歡在redux狀態對象上存儲導航器,並且不想將prop傳遞給表示組件。
有沒有一種方法可以將道具傳遞給這個容器組件?或者,有沒有其他方法可以忽略?
謝謝。
如何在mapDispatchToProps中訪問它? – Michael
@Michael以同樣的方式,你可以使用第二個參數 –