UNPKG

@designerstrust/remix-utils

Version:

This package contains simple utility functions to use with [Remix.run](https://remix.run).

38 lines (37 loc) 1.12 kB
import type { PromiseValue } from "type-fest"; /** * @see https://twitter.com/buildsghost/status/1507109734519750680 */ export declare type PromiseHash = Record<string, Promise<unknown>>; export declare type AwaitedPromiseHash<Hash extends PromiseHash> = { [Key in keyof Hash]: PromiseValue<Hash[Key]>; }; /** * Get a hash of promises and await them all. * Then return the same hash with the resolved values. * @example * export let loader: LoaderFunction = async ({ request }) => { * return json( * promiseHash({ * user: getUser(request), * posts: getPosts(request), * }) * ); * }; * @example * export let loader: LoaderFunction = async ({ request }) => { * return json( * promiseHash({ * user: getUser(request), * posts: promiseHash({ * list: getPosts(request), * comments: promiseHash({ * list: getComments(request), * likes: getLikes(request), * }), * }), * }) * ); * }; */ export declare function promiseHash<Hash extends PromiseHash>(hash: Hash): Promise<AwaitedPromiseHash<Hash>>;