redux-thunk dispatch method fires undefined action
<p>Here is the code I'm playing with</p>
<pre><code>import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import axios from 'axios'

const initialState = {
    user: {},
    requesting: false,
    err: null
}

const reducer = (state = initialState, action) =&gt; {
    switch (action.type) {
        case 'REQ_USER_INIT': return { ...state, requesting: true }
        case 'REQ_USER_DATA': return { ...state, requesting: false, user: action.user }
        case 'REQ_USER_ERR': return { ...state, requesting: false, err: action.err }
    }
    return state;
}

const logger = (store) =&gt; (next) =&gt; (action) =&gt; {
    let previous = JSON.stringify(store.getState())
    next(action)
    console.log(
        'action: ' + JSON.stringify(action) +
        '\n\tprevious: ' + previous +
        '\n\tcurrent: ' + JSON.stringify(store.getState())
    )
}

const store = createStore(reducer, applyMiddleware(logger, thunk))

store.dispatch((dispatch) =&gt; {
    dispatch({ type: 'REQ_USER_INIT' })

    // Fake Online REST API for Testing and Prototyping
    // break url to get an error response
    let usersEndpoint = 'https://jsonplaceholder.typicode.com/users/1'

    axios.get(usersEndpoint)
        .then((response) =&gt; {
            dispatch({
                type: 'REQ_USER_DATA',
                user:  {
                    id: response.data.id,
                    username: response.data.username,
                    email: response.data.email,
                }
            })
        })
        .catch((error) =&gt; {
            dispatch({
                type: 'REQ_USER_ERR',
                err: error.message
            })
    })
})
</code></pre>
<p>I believe it is pretty straightforward, right? I dispatch <code>REQ_USER_INIT</code> and then <code>REQ_USER_DATA</code> once the response is received. I should log two actions, however I get 3. Second action is <code>undefined</code> and I am strugling to figure out what causes it. Is it a bug with <strong>redux-thunk</strong> or am I doing something wrong?</p>
<p>Here is the output from my console:</p>
<pre><code>action: {&quot;type&quot;:&quot;REQ_USER_INIT&quot;}
·previous: {&quot;user&quot;:{},&quot;requesting&quot;:false,&quot;err&quot;:null}
·current: {&quot;user&quot;:{},&quot;requesting&quot;:true,&quot;err&quot;:null}
action: undefined
·previous: {&quot;user&quot;:{},&quot;requesting&quot;:false,&quot;err&quot;:null}
·current: {&quot;user&quot;:{},&quot;requesting&quot;:true,&quot;err&quot;:null}
action: {&quot;type&quot;:&quot;REQ_USER_DATA&quot;,&quot;user&quot;:{&quot;id&quot;:1,&quot;username&quot;:&quot;Bret&quot;,&quot;email&quot;:&quot;Sincere@april.biz&quot;}}
·previous: {&quot;user&quot;:{},&quot;requesting&quot;:true,&quot;err&quot;:null}
·current: {&quot;user&quot;:{&quot;id&quot;:1,&quot;username&quot;:&quot;Bret&quot;,&quot;email&quot;:&quot;Sincere@april.biz&quot;},&quot;requesting&quot;:false,&quot;err&quot;:null}
</code></pre>