ConceptPortal-public/rsconcept/frontend/src/hooks/usePartialUpdate.ts
2024-03-12 13:47:19 +03:00

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;