dvajs / dva

🌱 React and redux based, lightweight and elm-style framework. (Inspired by elm and choo)
https://dvajs.com/
MIT License
16.24k stars 3.17k forks source link

Call Effect from another effect #2452

Closed devcrazygit closed 2 years ago

devcrazygit commented 3 years ago

I want to call effect from another effect. In fact, this was mentioned here https://github.com/dvajs/dva/issues/878 But I want take updated state after calling the effect.

For example,

*firstEffect({payload}, {put, select}) {
    const {data}= yield select((state) => state.substate)    
    if (!data) {
        yield put({
            type: 'secondEffect'
        })
        console.log({data})
    }
    ...
   // work with `data`
},
*secondEffect() {
    // async logic
    ...
    // update state
    yield put({
        type: 'thirdReducer'
    })
}

In the above case, data remains as null in the console

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.