UNPKG

@designerstrust/remix-utils

Version:

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

32 lines (31 loc) 865 B
/** * 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 async function promiseHash(hash) { return Object.fromEntries(await Promise.all(Object.entries(hash).map(async ([key, promise]) => [key, await promise]))); }