Skip to content

Commit c83f8f8

Browse files
authored
UI: fix TocPopover, Sidebar to work in react 18 (#1416)
1 parent b9b0063 commit c83f8f8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/ui/src/components/layout/toc.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ const Context = createContext<{
149149
setOpen: (open: boolean) => void;
150150
} | null>(null);
151151

152+
const TocProvider = Context.Provider || Context;
153+
152154
export function TocPopover({
153155
open,
154156
onOpenChange,
@@ -157,7 +159,7 @@ export function TocPopover({
157159
}: MakeRequired<ComponentProps<typeof Collapsible>, 'open' | 'onOpenChange'>) {
158160
return (
159161
<Collapsible open={open} onOpenChange={onOpenChange} {...props}>
160-
<Context
162+
<TocProvider
161163
value={useMemo(
162164
() => ({
163165
open,
@@ -167,7 +169,7 @@ export function TocPopover({
167169
)}
168170
>
169171
{props.children}
170-
</Context>
172+
</TocProvider>
171173
</Collapsible>
172174
);
173175
}

packages/ui/src/layouts/docs/sidebar.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ export function SidebarFolderContent(props: CollapsibleContentProps) {
359359

360360
return (
361361
<CollapsibleContent {...props} className={cn('relative', props.className)}>
362-
<Context
362+
<Context.Provider
363363
value={useMemo(
364364
() => ({
365365
...ctx,
@@ -370,7 +370,7 @@ export function SidebarFolderContent(props: CollapsibleContentProps) {
370370
>
371371
<div className="absolute w-px inset-y-0 bg-fd-border start-3" />
372372
{props.children}
373-
</Context>
373+
</Context.Provider>
374374
</CollapsibleContent>
375375
);
376376
}

0 commit comments

Comments
 (0)