cumqueoptio
Version:
The meta-framework suite designed from scratch for frontend-focused modern web development.
26 lines (20 loc) • 547 B
text/typescript
type ObjectDispatchActions<T extends Record<string, any>> = {
[key in string & keyof T as `set${Capitalize<key>}`]: (
payload: T[key],
) => void;
};
const createObjectActions = (state: any) => {
const result: Record<string, any> = {};
Object.keys(state).forEach(key => {
result[`set${key[0].toUpperCase()}${key.substring(1)}`] = (
_state: any,
payload: any,
) => ({
..._state,
[key]: payload,
});
});
return result;
};
export { createObjectActions };
export type { ObjectDispatchActions };