mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
16 lines
367 B
TypeScript
16 lines
367 B
TypeScript
![]() |
import { useReducer } from 'react';
|
||
|
|
||
|
function usePartialUpdate<ValueType>(initialValue: ValueType) {
|
||
|
const [value, updateValue] = useReducer(
|
||
|
(data: ValueType, newData: Partial<ValueType>) => ({
|
||
|
...data,
|
||
|
...newData,
|
||
|
}),
|
||
|
initialValue
|
||
|
);
|
||
|
|
||
|
return [value, updateValue] as [ValueType, typeof updateValue];
|
||
|
}
|
||
|
|
||
|
export default usePartialUpdate;
|