import { useMemo, useReducer } from 'react'; var useMethods = function (createMethods, initialState) { var reducer = useMemo(function () { return function (reducerState, action) { var _a; return (_a = createMethods(reducerState))[action.type].apply(_a, action.payload); }; }, [createMethods]); var _a = useReducer(reducer, initialState), state = _a[0], dispatch = _a[1]; var wrappedMethods = useMemo(function () { var actionTypes = Object.keys(createMethods(initialState)); return actionTypes.reduce(function (acc, type) { acc[type] = function () { var payload = []; for (var _i = 0; _i < arguments.length; _i++) { payload[_i] = arguments[_i]; } return dispatch({ type: type, payload: payload }); }; return acc; }, {}); }, [createMethods, initialState]); return [state, wrappedMethods]; }; export default useMethods;