鍍金池/ 問答/HTML/ react-redux的mapdispatchtoprops函數(shù)如何獲取redu

react-redux的mapdispatchtoprops函數(shù)如何獲取redux中的store

redux-observable 是一個優(yōu)雅的利用 rxjs 處理 redux 異步 action 的解決方案,在學(xué)習(xí) redux-observable 處理 表單提交 的時候,遇到了一些自己不能解決的問題。

我們知道,redux-observable 重度依賴 redux 中的 action。我的意思是,redux-observable 依賴且只依賴 action 來處理數(shù)據(jù)。假如一個表單的數(shù)據(jù)都是放在 redux 的 store 里面的,那么在提交表單的時候,發(fā)出的 action 也需要帶上 store 里面的數(shù)據(jù),這樣才能被 redux-observable 正確接受并且進行處理。

那么問題來了,react-redux 在 mapDispatchToProps 的時候怎么才能拿到 store 里面的數(shù)據(jù)?

如果 mapDispatchToProps 解決不了這個問題,有其他通用的解決方案嗎?

回答
編輯回答
北城荒

各位大哥,小弟錯了。redux-observable 這么著名的 redux 中間件怎么會有這種問題呢。

function (action$: Observable<Action>, store: Store): Observable<Action>;

這是 redux-observable 的處理 action 的回調(diào)函數(shù),第二個參數(shù)就是 store。也就是說 redux-observable 可以同時獲取 action 和 store,像 reducer 一樣的處理數(shù)據(jù)流。

看一些例子遠遠不夠,還是要老老實實啃文檔 233

2017年8月15日 05:17