Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,40 @@ const accepted = await Confirm.call({ message: 'Continue?' })

Check out [the demo site](https://react-call.desko.dev/) to see some live examples of other React components being called.

# Lazy loading

Use React.lazy to code-split callable components and load them on demand.

```tsx
import { createCallable } from 'react-call'
import { lazy, Suspense } from 'react'

// 1) Lazy-load your component
const Confirm = createCallable(
lazy(() => import('./Confirm')), // default export required
)

// 2) Place Root inside a Suspense boundary
export function App() {
return (
<>
{/* Other app UI */}
<Suspense fallback={null}>
<Confirm.Root />
</Suspense>
</>
)
}

// 3) Call it as usual (component is fetched on first call)
const accepted = await Confirm.call({ message: 'Continue?' })
```

Notes:
- Make sure the lazily imported file has a default export (React.lazy requirement).
- Wrap `<Confirm.Root />` (or an ancestor) in `<Suspense>` to handle the loading state.
- The lazy component is split into a separate chunk and downloaded only when first called.

# Advanced usage

## End from caller
Expand Down