You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/docs/src/app/breadcrumbs/page.mdx
+38-36Lines changed: 38 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,17 +26,17 @@ The naive solutions all have problems:
26
26
27
27
## The Idea
28
28
29
-
With `foxact/breadcrumbs`, **you declare breadcrumbs the same way you declare your UI — as components, right where they belong.** Just like you write `<h1>Products</h1>` inside the Products layout, you write `<BreadcrumbItem title="Products" href="/products">` in the same place. Each breadcrumb segment is declared naturally alongside the UI it describes, and the full chain assembles itself automatically from the component tree. There's no separate config file to maintain, no global store to dispatch into.
29
+
With `foxact/breadcrumbs`, **you declare breadcrumbs the same way you declare your UI — as components, right where they belong.** Just like you write `<h1>Products</h1>` inside the Products layout, you write `<BreadcrumbSegment title="Products" href="/products">` in the same place. Each breadcrumb segment is declared naturally alongside the UI it describes, and the full chain assembles itself automatically from the component tree. There's no separate config file to maintain, no global store to dispatch into.
30
30
31
-
Under the hood, each `BreadcrumbItem` uses React Context to accumulate the chain: it reads the parent chain, appends its own `{ title, href }`, and provides the extended chain to its children. This is just nested context providers — the same mechanism React already uses for tree-shaped data.
31
+
Under the hood, each `BreadcrumbSegment` uses React Context to accumulate the chain: it reads the parent chain, appends its own `{ title, href }`, and provides the extended chain to its children. This is just nested context providers — the natural React tree hierarchy.
32
32
33
-
At the leaf (a page component), `BreadcrumbPage` reads the full accumulated chain and portals the rendered breadcrumb UI to a target element in the root layout via [Magic Portal](/magic-portal). No data flows "upward" — the chain is built top-down through context, and the UI is "teleported" to the global layout header via a React Portal.
33
+
At the leaf (a page component), `BreadcrumbCurrent` reads the full accumulated chain and portals the rendered breadcrumb UI to a target element in the root layout via [Magic Portal](/magic-portal). No data flows "upward" — the chain is built top-down through context, and the UI is "teleported" back up to the global layout header via a React Portal.
34
34
35
35
The result:
36
36
37
37
-**Declarative** — breadcrumbs are declared as components in your UI tree, not configured elsewhere.
38
-
-**Co-located** — each layout/page knows about its own segment.
39
-
-**Automatic collection** — nesting `BreadcrumbItem` components is all it takes; no boilerplate wiring.
38
+
-**Co-located** — your breadcrumb declarations live right at your UI.
39
+
-**Automatic collection** — nesting `BreadcrumbSegment` components is all it takes; no boilerplate wiring.
40
40
-**No extra renders** — no global state, no `useEffect` dispatches, no double-render workarounds.
41
41
42
42
importNextImagefrom'next/image';
@@ -51,7 +51,7 @@ import FoxactBreadcrumbsImage from '../../images/foxact-breadcrumbs.png';
51
51
52
52
### Setup
53
53
54
-
Create the breadcrumb primitives in a shared file. `createBreadcrumbs` returns an array, so you can name the components however you like:
54
+
Create the breadcrumb primitives in a shared file. `createBreadcrumbs` returns an array/tuple, so you can name the components and hooks however you like:
55
55
56
56
```tsx filename="src/breadcrumbs/index.tsx" copy
57
57
'use client';
@@ -65,10 +65,10 @@ export const [
65
65
BreadcrumbProvider,
66
66
// Target — specify where the breadcrumb UI will "teleport" to, typically you render this in the root layout
67
67
BreadcrumbTarget,
68
-
//Item — one per intermediate layout/route segment, declares a breadcrumb segment
69
-
BreadcrumbItem,
70
-
//Page — the leaf that completes the chain and renders the breadcrumb UI
71
-
BreadcrumbPage,
68
+
//Segment — one per intermediate layout/route segment, declares a breadcrumb segment
69
+
BreadcrumbSegment,
70
+
//Current — the leaf that completes the chain and renders the breadcrumb UI
71
+
BreadcrumbCurrent,
72
72
// Hook — read the current breadcrumb chain from context
73
73
useBreadcrumbs
74
74
] =createBreadcrumbs(
@@ -107,31 +107,33 @@ export default function AppLayout({ children }: React.PropsWithChildren) {
107
107
108
108
### Intermediate Layouts / Route Segments
109
109
110
-
In each intermediate layout / route segment, wrap `children` with `BreadcrumbItem` to declare a breadcrumb segment:
110
+
In each intermediate layout / route segment, wrap `children` with `BreadcrumbSegment` to declare a breadcrumb segment:
> Under the hood, `BreadcrumbSegment` is a React context provider that accumulates the breadcrumb chain. That's why you must provide subtree via `children`.
125
+
124
126
### Leaf Page
125
127
126
-
In the leaf page, use `BreadcrumbPage` to complete the chain and render the breadcrumb UI. Pass a **render function** as children to receive the full item array:
128
+
In the leaf page, use `BreadcrumbCurrent` to complete the chain and render the breadcrumb UI. Pass a **render function** as children to receive the full item array:
0 commit comments