Getting Parsing error: Unexpected token, expected "," error

Viewed 39

I am getting Parsing error: Unexpected token, expected "," error at but I am unable to locate the place where I am missing "," . Please see the picture below to see the exact line of error.

const cartSlice = createSlice({
    name: 'cartReducer',
    initialState,
    reducers: {
        CART_ADD_ITEM: (state, action) => {
            //checkout action.payload
        },
    },
    extraReducers: {
        [addToCart.pending]: (state) => {
            console.log(state);
            state.loading = true;
        },
        [addToCart.fulfilled]: (state, action) => {
            console.log(state);
            const item = action.payload;
            const existItem = state.cartItems.find(
                (cartItem) => cartItem.product === item.product
            ); {
                existItem
                    ?
                    (state.cartItems = state.cartItems.map((cartItem) => {
                        return {
                            cartItem.product === existItem.product ? item : cartItem
                        }
                    })) :
                    ((state.loading = false),
                        (state.cartItems = [...state.cartItems, item]));
            }
        },

        [addToCart.rejected]: (state, action) => {
            state.loading = true;
            state.error = action.payload;
        },
    }
});

Error Picture

Error after removing braces from return statement

1 Answers
return {
    cartItem.product === existItem.product ? item : cartItem
}

The above statement is wrong, you don't need {} there. write it in a single line, like this:

return cartItem.product === existItem.product ? item : cartItem;
Related