ConceptPortal-public/rsconcept/frontend/src/hooks/usePartialUpdate.ts

18 lines
381 B
TypeScript
Raw Normal View History

'use client';
import { useReducer } from 'react';
function usePartialUpdate<ValueType>(initialValue: ValueType) {
const [value, updateValue] = useReducer(
(data: ValueType, newData: Partial<ValueType>) => ({
...data,
2023-12-28 14:04:44 +03:00
...newData
}),
initialValue
);
return [value, updateValue] as [ValueType, typeof updateValue];
}
2023-12-28 14:04:44 +03:00
export default usePartialUpdate;