mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 04:50:36 +03:00
18 lines
381 B
TypeScript
18 lines
381 B
TypeScript
'use client';
|
|
|
|
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;
|