Skip to content

Instantly share code, notes, and snippets.

@KacperKozak
Created September 5, 2023 13:15
Show Gist options
  • Save KacperKozak/c6fab3b514c8b5723bbb76c0d803a574 to your computer and use it in GitHub Desktop.
Save KacperKozak/c6fab3b514c8b5723bbb76c0d803a574 to your computer and use it in GitHub Desktop.
`useObject` hook
import { useReducer } from 'react';
type Reducer<T> = (state: T, update: Partial<T>) => T;
export const useObject = <T>(initial: T) => {
return useReducer<Reducer<T>>((state, update) => ({ ...state, ...update }), initial);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment