Loader with Parameters

    0

    1

    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

    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));
    };
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.