Accessing a reducer state from within another reducer
<p>I have a reducer whereby I am retuning the appropriate state when an action is dispatched. Now I am calling an API at regular intervals so the result will trigger an action again and again. So what I want is that if the reducer state already has data then another reducer doesn't show the state as loading while the call is sent. It must maintain its loading state when receiving data the first time only. I hope I am able to explain it properly</p>

<p>Here are my code snippets</p>

<p><strong>Loading state reducer</strong></p>

<pre><code>const loading = (state = false, action) =&gt; {

    switch (action.type) {
    case 'GET_AUDIT_DATA':         // here I want to return true only when there is no data available
        return true
    case 'GET_AUDIT_DATA_RECEIVED':  
        return false
    case 'GET_AUDIT_DATA_ERROR':
        return false
    default:
        return state
    }
}
</code></pre>

<p><strong>Combining reducers</strong></p>

<pre><code>const allReducers = combineReducers({
    auditData: AuditData,
    auditLoading: AuditLoading,
    modifiedOrders: ModifiedOrders
});

export default allReducers;
</code></pre>

<p><strong>Reducer returning data on action triggered by superagent</strong></p>

<pre><code>const auditData = (state = [], action) =&gt; {
    switch(action.type) {
        case 'GET_AUDIT_DATA_RECEIVED': 
        console.log(action.data);
            return action.data;
        case 'GET_AUDIT_DATA_ERROR': 
            return action.err;
        default :
            return state;
    }
}
export default auditData;
</code></pre>

<p>So initially the <code>auditData</code> doesn't contain any data, only after the first success call it returns the data. When this is called at the same time <code>loading state reducer</code> is called and it should return true in <code>GET_AUDIT_DATA</code> action only when the audit data reducer doesn't contain any data.</p>

<p>Also is returning just the current obtained data from <code>auditData</code> the right way to go or I should do it differently. Basically I want to <code>overwrite</code> the <code>current data</code> with the <code>new one</code>.</p>