Created
September 5, 2023 13:15
-
-
Save KacperKozak/c6fab3b514c8b5723bbb76c0d803a574 to your computer and use it in GitHub Desktop.
`useObject` hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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