remix-utils-rt
Version:
This package contains simple utility functions to use with [React Router](https://reactrouter.com/home).
17 lines (16 loc) • 930 B
TypeScript
import type { UNSAFE_DataWithResponseInit } from "react-router";
type ActionsRecord = Record<string, () => Promise<UNSAFE_DataWithResponseInit<unknown>>>;
type ResponsesRecord<Actions extends ActionsRecord> = {
[Action in keyof Actions]: Actions[Action] extends () => Promise<UNSAFE_DataWithResponseInit<infer Result>> ? Result : never;
};
type ResponsesUnion<Actions extends ActionsRecord> = ResponsesRecord<Actions>[keyof Actions];
/**
* Runs an action based on the FormData's action name
* @param formData The FormData to parse for an action name
* @param actions The map of actions to run
* @returns The response from the action
* @throws {ReferenceError} Action name not found
* @throws {ReferenceError} Action "${name}" not found
*/
export declare function namedAction<Actions extends ActionsRecord>(formData: FormData, actions: Actions): Promise<UNSAFE_DataWithResponseInit<ResponsesUnion<Actions>>>;
export {};