0
1
JRJose Romero
In this code, "loader" is a function that returns a loading indicator. The code declares a "loader" function and specifies that the function should take two parameters, an identifier and a callback. The "loader" function is based on an asynchronous function call, and it invariantly checks to see that the identifier that is passed in matches the expected identifier. If it does, the "loader" function returns a JSON object that contains the data that was requested by the "getDataById" function.
Library: remix
Shortcut: remix.loader.with-params
import { json, LoaderFunction } from "remix";
import invariant from "tiny-invariant";
export const loader: LoaderFunction = async ({ params }) => {
invariant(params.id, "expected identifier");
return json(await getDataById(id));
};