Wait for a redux action to finish dispatching
<p>I have the following action creator:</p>

<pre><code>export function scrolltoNextItem(item) {
  return (dispatch, getState) =&gt; {
    dispatch(appendItem(Item));
    dispatch(
      scrollToNextIndex(
        getState().items.length - 1
      )
    )
  }
}
</code></pre>

<p>Problem is that <code>scrollToNextItem</code> runs before appendItem has finished and the scroll position ends up being incorrect. I can prove this is the case by adding a <code>setTimeout</code> to make the execution of the script wait for the next tick before running <code>scrollToNextItem</code>:</p>

<pre><code>export function scrolltoNextItem(item) {
  return (dispatch, getState) =&gt; {
    dispatch(appendItem(Item));
    setTimeout(() =&gt; {
      dispatch(
        scrollToNextIndex(
          getState().items.length - 1
        )
      )
    }, 0);
  }
}
</code></pre>

<p>How can I wait for the <code>appendItem</code> action to finish? In standard react land I would just use the <code>setState</code> callback:</p>

<pre><code>this.setState({something: 'some thing'}, () =&gt; {
  console.log('something is set');
});
</code></pre>

<p>But <code>dispatch</code> doesn't provide any callback functionality.</p>