import { json, LoaderFunction } from "remix";
      import invariant from "tiny-invariant";
      export const loader: LoaderFunction = async ({ params }) => {
        invariant(, "expected identifier");
        return json(await getDataById(id));
      Typescript language logo
      your recipe card header background

      Loader with Parameters



      Jose Romero
      Remix TypeScript public recipes

      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


        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.