From 9cf184eb38f209f47a0c901c011310d7ef3ae2a8 Mon Sep 17 00:00:00 2001 From: Arif Rahman Hakim Date: Wed, 10 Jul 2024 14:57:54 +0800 Subject: [PATCH] fix: use deep clone prevent mutate filter --- src/types/filter.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/types/filter.ts b/src/types/filter.ts index 83f3769..8e3a46d 100644 --- a/src/types/filter.ts +++ b/src/types/filter.ts @@ -14,6 +14,10 @@ const initialFilterConfig: Record> = { activity: { team: [], category: [] }, }; -export const createInitialFilter = (type: FilterType): Filter => { - return initialFilterConfig[type]; +const deepClone = (obj: T): T => { + return JSON.parse(JSON.stringify(obj)); }; + +export const createInitialFilter = (type: FilterType): Filter => { + return deepClone(initialFilterConfig[type]); +}