parent
768ef98f51
commit
8154fd4dbd
1 changed files with 10 additions and 6 deletions
@ -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…
Reference in new issue