[英]Actions as callbacks in react-router routes components
我想將redux動作用作對react-router路由中的onChange
事件的回調。 我也在使用react-router-redux。
就像是
<Route path="profile/search" component={ProfileSearch} onChange={store.dispatch(fetchCompanies())} />
其中fetchCompanies
是行動。
更一般而言,我想聽路線變化並最終與狀態互動,這就是為什么使用動作對我來說似乎是最直接的選擇。 但是,我收到此錯誤:
Uncaught TypeError: hook.apply is not a function TransitionUtils.js?f913:22
還有另一種方法可以做到這一點嗎? 試圖將操作作為回調傳遞給路由更改本質上不好嗎? 如果沒有,我該如何運作?
調用store.dispatch
會引發錯誤,但是將分派的動作包裝在函數中是store.dispatch
的。
const onChangeProfileSearch = () => store.dispatch(fetchCompanies());
<Route path="profile/search" component={ProfileSearch} onChange={onChangeProfileSearch} />
但是,可能有更好的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.