import { useReducer } from "react"; export function useCompositeState(args: object) { const red = (state: object, action: any) => { return { ...state, ...action.payload }; }; const [state, dispatch] = useReducer(red, { ...args }); return new Proxy(state, { get: (_, key): any => { return state[key]; }, set: (_, key, value): boolean => { dispatch({ payload: { [key]: value } }); return true; }, }); }