fix(striker-ui): allow remove key in object setter builder

main
Tsu-ba-me 2 years ago
parent 768ef98f51
commit 8154fd4dbd
  1. 16
      striker-ui/lib/buildObjectStateSetterCallback.ts

@ -1,9 +1,13 @@
const buildObjectStateSetterCallback =
<S extends Record<string, unknown>>(key: keyof S, value: S[keyof S]) =>
({ [key]: toReplace, ...restPrevious }: S): S =>
({
...restPrevious,
[key]: value,
} as S);
<S extends Record<string, unknown>>(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;

Loading…
Cancel
Save