-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathEndpoint.tsx
47 lines (42 loc) · 1.37 KB
/
Endpoint.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { createEndpointContext, type ApiDefinition } from "@fern-api/fdr-sdk/api-definition";
import type * as FernNavigation from "@fern-api/fdr-sdk/navigation";
import { memo, useMemo } from "react";
import { SlugProvider } from "./AnchorIdParts";
import { EndpointContent } from "./EndpointContent";
export declare namespace Endpoint {
export interface Props {
showErrors: boolean;
node: FernNavigation.EndpointNode;
apiDefinition: ApiDefinition;
breadcrumb: readonly FernNavigation.BreadcrumbItem[];
streamToggle?: React.ReactElement;
last?: boolean;
}
}
const UnmemoizedEndpoint: React.FC<Endpoint.Props> = ({
showErrors,
node,
apiDefinition,
breadcrumb,
streamToggle,
last,
}) => {
const context = useMemo(() => createEndpointContext(node, apiDefinition), [node, apiDefinition]);
if (!context) {
// eslint-disable-next-line no-console
console.error("Could not create context for endpoint", node);
return null;
}
return (
<SlugProvider slug={node.slug}>
<EndpointContent
breadcrumb={breadcrumb}
showErrors={showErrors}
context={context}
streamToggle={streamToggle}
last={last}
/>
</SlugProvider>
);
};
export const Endpoint = memo(UnmemoizedEndpoint);