probo / rules
getprobo/probo/.cursor/rules/react-named-exports-lazy-entry.mdc
Named exports for components; default export only for lazy() bundle entries
Cursor rule1.4k starsChanged 3 months ago
What's in it
- Named exports; export default only for lazy() entries
---
description: Named exports for components; default export only for lazy() bundle entries
globs: "**/*.tsx"
alwaysApply: false
---
# Named exports; `export default` only for lazy() entries
React components use **named exports**. `export default` is reserved as an
exception **only** for the component a router/`lazy()` imports as a bundle entry,
because `lazy(() => import("./X"))` resolves the module's default export.
In the Loader + Page/Layout pattern this means exactly **one** default export per
chain — the Loader (the `lazy()` target). The Page/Layout it renders is imported
**directly by the Loader**, not through `lazy()`, so it must be a named export.
```tsx
// GOOD — Loader is the lazy() entry → default export
// MainLayoutLoader.tsx
import { MainLayout, mainLayoutQuery } from "./MainLayout";
export default function MainLayoutLoader() { /* useQueryLoader → <MainLayout /> */ }
// GOOD — Layout/Page imported directly by the Loader → named export
// MainLayout.tsx
export const mainLayoutQuery = graphql`query MainLayoutQuery { ...TopBar_query }`;
export function MainLayout({ queryRef }: MainLayoutProps) { /* usePreloadedQuery */ }
// routes.tsx — only the Loader is referenced by lazy()
Component: lazy(() => import("#/pages/MainLayoutLoader")),
```
```tsx
// BAD — Page/Layout defaulted even though the Loader (not lazy) imports it
// MainLayout.tsx
export default function MainLayout(/* ... */) {}
// MainLayoutLoader.tsx
import MainLayout, { mainLayoutQuery } from "./MainLayout";
```
A page with no loader (no Relay data) that `lazy()` imports directly is itself
the bundle entry, so it keeps the `export default`. The rule is about *who
`lazy()` imports*, not about the "Page" vs "Layout" label.
See `contrib/claude/react-components.md` (File and export) and
`contrib/claude/app-arborescence.md`.
More agent context in getprobo/probo
29 other files this repository gives its agents.
AGENTS.md
CLAUDE.md
Cursor rule
- .cursor/rules/code-comments.mdc
- .cursor/rules/config-propagation.mdc
- .cursor/rules/coredata-migrations.mdc
- .cursor/rules/detail-page-back-link.mdc
- .cursor/rules/git-commit-signing.mdc
- .cursor/rules/git-commit-style.mdc
- .cursor/rules/go-authorize-scope.mdc
- .cursor/rules/go-coredata-load-naming.mdc
- .cursor/rules/go-declarations.mdc
- .cursor/rules/go-delete-no-rows-check.mdc
- .cursor/rules/go-error-handling.mdc
- .cursor/rules/go-imports.mdc
- .cursor/rules/go-logging.mdc
- .cursor/rules/go-multiline-params.mdc
- .cursor/rules/go-naming-conventions.mdc
- .cursor/rules/go-pg-constraint-check.mdc
- .cursor/rules/go-upsert-returning-id.mdc
- .cursor/rules/go-url-construction.mdc
- .cursor/rules/list-filtering.mdc
- .cursor/rules/no-outlet-context-data.mdc
- .cursor/rules/prompt-style.mdc
- .cursor/rules/relay-connection-item-components.mdc
- .cursor/rules/relay-fragments-not-data-props.mdc
- .cursor/rules/relay-required-directive.mdc
- .cursor/rules/skeleton-width-sync.mdc
- .cursor/rules/template-files.mdc
- .cursor/rules/v2-color-scale.mdc
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
Reports can't be read right now.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool registry_write, action report. How to connect one.

