Filtering Arrays in a Reducer - Redux
<p>Following a React tutorial, I see this code in a reducer to remove a message from an array using its ID:</p>

<p><a href="https://i.stack.imgur.com/yd0pm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yd0pm.png" alt="enter image description here"></a>
Wouldn't this be better written as:</p>

<p><code>else if (action.type === 'DELETE_MESSAGE') {
    return {
      messages: [
        ...state.messages.filter(m =&gt; m.id === action.id)
      ],
    };
};
</code></p>

<p>I thought for a second that <code>filter</code> might modify state and return the same array but according to <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter" rel="noreferrer">MDN</a> it creates a new array.</p>

<p>Am I safe, and is my implementation correct?</p>