openpanel/packages/remix/src/refine-routes.tsx
Stefan Pejcic 8595a9f4e5 back
2024-05-08 19:58:53 +02:00

40 lines
1.1 KiB
TypeScript

import React from "react";
import { useLocation } from "@remix-run/react";
import { useResource } from "@refinedev/core";
type RefineRoutesProps = {
children?: (
renderedRoute: JSX.Element | undefined,
pathname: string | undefined,
) => JSX.Element;
};
export const RefineRoutes = ({ children }: RefineRoutesProps) => {
const { resource, action } = useResource();
const { pathname } = useLocation();
const resourceAction = resource && action ? resource[action] : undefined;
const ResourceActionComponent =
typeof resourceAction === "function"
? resourceAction
: typeof resourceAction === "object"
? resourceAction.component
: undefined;
return (
<>
{children ? (
children(
ResourceActionComponent ? (
<ResourceActionComponent />
) : undefined,
pathname ?? undefined,
)
) : ResourceActionComponent ? (
<ResourceActionComponent />
) : undefined}
</>
);
};