Skip to content

Commit 5c65fe7

Browse files
committed
chore: draw a lazy component's own loading shape in react-component skill
1 parent 4d1a461 commit 5c65fe7

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

‎skills/react-component/SKILL.md‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,33 +141,26 @@ When a component pulls in a heavy dependency (a rich-text editor, a chart librar
141141
```tsx
142142
// loadable.tsx
143143
import {
144-
type ReactNode,
145144
Suspense,
146145
lazy
147146
} from 'react'
148147
import type { MDXEditorProps } from './MDXEditor'
149-
150-
export interface LoadableMDXEditorProps extends MDXEditorProps {
151-
fallback?: ReactNode
152-
}
148+
import { MDXEditorLoading } from './MDXEditorLoading'
153149

154150
const LazyMDXEditor = lazy(() => import('./MDXEditor').then(({ MDXEditor }) => ({
155151
default: MDXEditor
156152
})))
157153

158-
export function MDXEditor({
159-
fallback,
160-
...props
161-
}: LoadableMDXEditorProps) {
154+
export function MDXEditor(props: MDXEditorProps) {
162155
return (
163-
<Suspense fallback={fallback}>
156+
<Suspense fallback={<MDXEditorLoading />}>
164157
<LazyMDXEditor {...props} />
165158
</Suspense>
166159
)
167160
}
168161
```
169162

170-
The wrapper keeps the original component name and props, adding only an optional `fallback` prop for the `Suspense` fallback.
163+
The wrapper keeps the original component name and props and adds none. It draws its own `<Name>Loading` beside it, the shape of what is coming: no `fallback` prop, and never `fallback={null}`, which leaves a hole that fills in late.
171164

172165
## Component anatomy
173166

0 commit comments

Comments
 (0)