Skip to content

Commit

Permalink
prevent duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Nov 1, 2023
1 parent bc3015c commit 00e7d5b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/state/campaigns/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@ export default createReducer<CampaignsState>(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 }) => {
Expand Down

0 comments on commit 00e7d5b

Please sign in to comment.