我有一個自定義滾動條。有兩個組件。平面列表和嵌套目錄。該列表有一個onscroll處理程序,用於分派「滾動」操作。 reducer然後返回一個新的狀態,該狀態反映該目錄是否應該具有靜態位置或固定位置以及當前部分是什麼。現在,我不知道如何告訴目錄模塊當前部分已經改變。似乎不推薦從列表縮減器分派動作。我不知道如何在目錄模塊中添加監聽器,因爲我不知道如何直接訪問商店。我只通過上下文在反應組件中擁有它。我正在使用react redux入門套件。將數據從動作傳播到另一個縮減器
更新:我的源代碼
TrackList/component.js
componentDidMount() {
let {scrolled} = this.props;
window.onScroll = scrolled;
}
TrackList/module.js
scrolled(state, action) {
if (conditions) {
new_state = make_directory_static_reducer(state);
}
else {
new_state = make_directory_fixed_reducer(state);
}
let current_section = get_current_section();
new_state = current_section_reducer(new_state, current_section);
return new_state;
}
TrackDir/module.js
action_handlers = {
set_current_section() {
// I don't know how to run this when current section is set
}
}
你試過['connect()'](https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options)方法來連接你的將組件反應到Redux商店? –
當然,這就是我將調度員和狀態連接到反應組件的方式。但是當我說從'react-redux'導入{connect};導出默認連接(map_state_to_props,map_dispatch_to_props)(TrackList);仍然沒有明顯的方式訪問該模塊中的商店。 – Sixtease
要更新商店,您需要發送一個操作。要從商店獲得價值,你可以使用'connect()'。通常,直接在組件中訪問商店不是一個好主意。 –