diff --git a/src/buildStrongRoute.tsx b/src/buildStrongRoute.tsx index f27b9c2..5b5221d 100644 --- a/src/buildStrongRoute.tsx +++ b/src/buildStrongRoute.tsx @@ -96,7 +96,7 @@ export const buildStrongRoute = < RouteId >, ): StrongRemixRouteExports> => { - const { loader, action, Component, ErrorBoundary } = opts; + const { loader, action, Component, ErrorBoundary, meta } = opts; const output = {} as StrongRemixRouteExports; if (loader) { @@ -107,6 +107,10 @@ export const buildStrongRoute = < output["action"] = async (args) => handleDataFunctionForRemix(action, args); } + if (meta) { + output["meta"] = (args) => meta(args); + } + if (Component) { output["Component"] = () => { // eslint-disable-next-line react-hooks/rules-of-hooks diff --git a/src/index.test.tsx b/src/index.test.tsx index 68d664a..88c2a8d 100644 --- a/src/index.test.tsx +++ b/src/index.test.tsx @@ -21,6 +21,7 @@ import { strongLoader, } from "./"; import { strongResponse } from "./strongResponse"; +import { StrongMeta } from "./types"; describe("strongResponse", () => { it("should create and format a response with a data object and status code", async () => { @@ -116,6 +117,14 @@ describe("buildStrongRoute", () => { return redirect(redirectResponse); }); + const meta: StrongMeta = ({ data }) => { + if (data) { + console.log(data.data); + } + + return []; + }; + const Component: StrongComponent = (props) => { if (props.status === HttpStatusCode.ACCEPTED) return null; @@ -142,6 +151,7 @@ describe("buildStrongRoute", () => { ErrorBoundary, loader, action, + meta, }); // TODO - add test cases for routeWithoutAction @@ -453,4 +463,11 @@ describe("buildStrongRoute", () => { `); }); }); + + describe("meta", () => { + it("should return a empty aray", async () => { + const res = (route1 as any).meta({ data: {} } as any); + expect(res).toStrictEqual([]); + }); + }); }); diff --git a/src/types.ts b/src/types.ts index 8bba4f7..db2871e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,10 +2,13 @@ import { V2_MetaFunction } from "@remix-run/react"; import { RouteComponent, V2_ErrorBoundaryComponent, + V2_MetaArgs, + V2_MetaDescriptor, } from "@remix-run/react/dist/routeModules"; import { ActionArgs, ActionFunction, + DataFunctionArgs, LoaderArgs, LoaderFunction, } from "@remix-run/server-runtime"; @@ -53,6 +56,12 @@ export type StrongLoader< Redirect extends StrongRedirect = never, > = (args: LoaderArgs) => Promise>; +export type StrongMeta< + Success extends StrongResponse = never, +> = ( + args: V2_MetaArgs<(args: DataFunctionArgs) => Promise>, +) => V2_MetaDescriptor[]; + export type StrongAction< Failure extends StrongResponse = never, Success extends StrongResponse = never, @@ -99,6 +108,7 @@ export type BuildStrongRemixRouteExportsOpts< action?: StrongAction; Component?: StrongComponent; ErrorBoundary?: StrongErrorBoundary; + meta?: StrongMeta; }; export type StrongRemixRouteExports<