From 5ca5d0d0b923141d59f602bda3e1a031b8605e04 Mon Sep 17 00:00:00 2001 From: Jonasz Bigda Date: Tue, 26 Jul 2022 17:06:06 +0200 Subject: [PATCH] small fix --- src/redux/slices/userSlice.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/redux/slices/userSlice.ts b/src/redux/slices/userSlice.ts index e113ba3..0b1e953 100644 --- a/src/redux/slices/userSlice.ts +++ b/src/redux/slices/userSlice.ts @@ -27,17 +27,21 @@ export const userSlice = createSlice({ (restaurant) => restaurant.id === action.payload.id ); let restaurants: Restaurant[] = state.restaurants || []; - state = { - ...state, - restaurants: [ - ...restaurants.slice(0, index), - action.payload, - ...restaurants.slice(index + 1), - ], - }; + if (index != undefined) { + state = { + ...state, + restaurants: [ + ...restaurants.slice(0, index), + action.payload, + ...restaurants.slice(index + 1), + ], + }; + } else { + state = state; + } }, }, }); -export const { clearUserData } = userSlice.actions; +export const { clearUserData, updateRestaurant } = userSlice.actions; export default userSlice.reducer;