Wait for a redux action to finish dispatching. You can always wrap appendItem into a promise and pass dispatch as an argument to it.
1 2 3 4 5 | const appendItem = (item, dispatch) => new Promise((resolve, reject) => { // do anything here dispatch(<your-action>); resolve(); } |
Then you can call it like this from scrolltoNextItem
1 2 3 4 5 6 7 8 9 10 11 | export function scrolltoNextItem(item) { return (dispatch, getState) => { appendItem(Item, dispatch).then(() => { dispatch( scrollToNextIndex( getState().items.length - 1 ) ) }) } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.