The main issue is that you are using arrow functions "without a body" (in other words, without using {}). This means that your arrow function is implicitly returning the resulting value of any expression succeeding the => symbol. In this case it will be action.payload.quantity or cartItem depending if the item ID is matched or not.
Additionally, I assume that you are using the result of the map operation (a new array with the returned items) to update your state.
If you are using Redux Toolkit or something else to ensure immutability (I assume you do because your code however is not respecting immutability as inner items are being returned as references and not as new values), you could replace your map function with a for loop or other loop structure (like Array.prototype.find) that allows you to interrupt the loop after finding the item you was looking for.
If you want to fix your code and leave it as it is (not recommended), you can do as follows:
state.cart.map(cartItem => {
if (cartItem.id === action.payload.id) {
cartItem.quantity = action.payload.quantity;
}
return cartItem;
});