Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
75
rated 0 times [  82] [ 7]  / answers: 1 / hits: 21031  / 6 Years ago, thu, october 4, 2018, 12:00:00

My Saga Root looks like this



export default function* root() {
yield takeLatest(LOAD_SEARCHRESULTS, getSearchResults);
}


it watches LOAD_SEARCHRESULTS action and then calls getSearchResults function.



Is there any way I can watch multiple actions in root?
Something like this:



export default function* root() {
yield takeLatest(LOAD_SEARCHRESULTS, getSearchResults);
yield takeLatest(CHANGE_ALIASFILTER, getSearchResults);
yield takeLatest(CHANGE_CATFILTER, getSearchResults);
}


So if any of those action comes in - it calls getSearchResults. I have tried yield all([]) and takeEvery but it only watches for first action.


More From » reactjs

 Answers
2

takeLatest can also take an array of actions, so you just need to do



export default function* root() {
yield takeLatest([LOAD_SEARCHRESULTS, CHANGE_ALIASFILTER, CHANGE_CATFILTER], getSearchResults);
}


Another option is to use all and fork, like here


[#53370] Monday, October 1, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anniejulietteb

Total Points: 740
Total Questions: 125
Total Answers: 97

Location: Benin
Member since Fri, Mar 24, 2023
1 Year ago
;