title: Add object to array in Redux?
body: <p>I'm trying to add a element to a array, which is called allLogbooks. This array contains objects called Logbook. My issue is, how do I fit in code so that it adds the new element to the array which is declared in my reducer? This is my initial state:</p>
  
  <pre><code>const initialState = {
    isFetching: false,
    error: undefined,
    isRegistered: false,
    isUpdated: false,
    hasChecked: false,
    isError: false,
    registerStepOne: true,
    registerStepTwo: false,
    registerStepThree: false,
    registerStepFour: false,
    logbooks: undefined,
    allLogbooks: [],
    userInfo: undefined,
    logbookAddSuccess: false,
    newLogbook: undefined,
    graphFilter: 1
  }
  </code></pre>
  
  <p>This is my reducer:</p>
  
  <pre><code>case ADD_LOGBOOK_SUCCESS:
      allLogbooks.push(action.newLogbook);
        return {
          ...state,
          isFetching: false,
          logbookAddSuccess: true,
          isUpdated: true,
          isError: false,
        }
  </code></pre>
  
  <p>And this is my action:</p>
  
  <pre><code>function addLogbookSuccess(newLogbook) {
      return {
          type: ADD_LOGBOOK_SUCCESS
          }
  }
  </code></pre>
  
  <p>I then make a POST call to a nodejs server, where it will respond with a message if it was successful, and the logbook which was just created. the following data is what it returns:</p>
  
  <pre><code>{
      "success": true,
      "logbook": {
          "created_by": "",
          "created_at": "",
          "_id": "",
          "__v": 0
      }
  }
  </code></pre>
  
  <p>I then dispatch in the API call, as such:</p>
  
  <pre><code>.then(data =&gt; data.json())
              .then(json =&gt; {
                  Keyboard.dismiss();
                  dispatch(addLogbookSuccess(json.logbook));
  
              })
              .catch(err =&gt; dispatch(addLogbookFailed(err)))
  </code></pre>
  
  <p>I've substituted this by using AsyncStorage to access the array abroad all my views, but I know this is wrong. </p>