Call function after dispatch from redux has finished

后端 未结 5 573
-上瘾入骨i
-上瘾入骨i 2020-12-14 20:48

All around it but not quite as I have enough of an idea of redux-thunk and of react-router but I am not getting this seemingly simple idea of:

5条回答
  •  轮回少年
    2020-12-14 21:16

    I think what you are looking for is Redux Saga.

    You can use the TakeEvery Effect, which will trigger the function you want every time a specific action is called.

    Example :

    import { takeEvery } from `redux-saga/effects`
    
    function* fetchUser(action) {
      ...
    }
    
    function* watchFetchUser() {
      yield takeEvery('USER_REQUESTED', fetchUser)
    }
    

    Take a look at the doc and read this article

提交回复
热议问题