From 8154fd4dbd148770cc12b135396148e3a4b13b21 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Wed, 15 Mar 2023 19:21:44 -0400 Subject: [PATCH] fix(striker-ui): allow remove key in object setter builder --- striker-ui/lib/buildObjectStateSetterCallback.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/striker-ui/lib/buildObjectStateSetterCallback.ts b/striker-ui/lib/buildObjectStateSetterCallback.ts index 15170e85..98cecfcf 100644 --- a/striker-ui/lib/buildObjectStateSetterCallback.ts +++ b/striker-ui/lib/buildObjectStateSetterCallback.ts @@ -1,9 +1,13 @@ const buildObjectStateSetterCallback = - >(key: keyof S, value: S[keyof S]) => - ({ [key]: toReplace, ...restPrevious }: S): S => - ({ - ...restPrevious, - [key]: value, - } as S); + >(key: keyof S, value?: S[keyof S]) => + ({ [key]: toReplace, ...restPrevious }: S): S => { + const result = { ...restPrevious } as S; + + if (value !== undefined) { + result[key] = value; + } + + return result; + }; export default buildObjectStateSetterCallback;