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 = const buildObjectStateSetterCallback =
<S extends Record<string, unknown>>(key: keyof S, value: S[keyof S]) => <S extends Record<string, unknown>>(key: keyof S, value?: S[keyof S]) =>
({ [key]: toReplace, ...restPrevious }: S): S => ({ [key]: toReplace, ...restPrevious }: S): S => {
({ const result = { ...restPrevious } as S;
...restPrevious,
[key]: value, if (value !== undefined) {
} as S); result[key] = value;
}
return result;
};
export default buildObjectStateSetterCallback; export default buildObjectStateSetterCallback;

Loading…
Cancel
Save