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

16 lines
367 B
TypeScript
Raw Normal View History

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;