From 00e7d5b3a6e7105d3cf8abad66e952a18ad6169c Mon Sep 17 00:00:00 2001 From: Danh Date: Wed, 1 Nov 2023 11:47:09 +0700 Subject: [PATCH] prevent duplicate --- src/state/campaigns/reducer.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/state/campaigns/reducer.ts b/src/state/campaigns/reducer.ts index e9d12693dc..1bb05e7bfc 100644 --- a/src/state/campaigns/reducer.ts +++ b/src/state/campaigns/reducer.ts @@ -69,9 +69,15 @@ export default createReducer(initialState, builder => } }) .addCase(setCampaignDataByPage, (state, { payload: { campaigns, isReset } }) => { + const oldData = state.data + const newData = isReset + ? campaigns + : oldData.some(e => e.id === campaigns[0]?.id) + ? oldData + : oldData.concat(campaigns) return { ...state, - data: isReset ? campaigns : state.data.concat(campaigns), + data: newData, } }) .addCase(setLoadingCampaignData, (state, { payload: loading }) => {