Skip to main content
cmdk is designed to work naturally with async data. You render items as they become available and cmdk handles filtering, sorting, and selection automatically — no special integration required.

Basic async pattern

Use useState for your items and a loading flag, then fetch in a useEffect. Render Command.Loading while the request is in flight:
As items mount, they are registered with the store and filtered against the current search query. Items that arrive while the user is already typing are scored and sorted immediately.

Determinate progress

Pass a progress prop (0–100) to Command.Loading to indicate how much has loaded. This sets the aria-valuenow attribute on the underlying progressbar role:

Always-visible items with forceMount

If some items should always be visible regardless of filtering — for example, recent searches shown while loading — use forceMount on those items:

Debouncing search with useCommandState

For search-as-you-type API calls, debounce the query to avoid issuing a request on every keystroke. Read the current search value with useCommandState:
useCommandState must be called inside a component that is a descendant of Command. It uses useSyncExternalStore internally and re-renders only when the selected slice of state changes.
When fetching server-side results based on search input, set shouldFilter={false} on Command. The server returns only matching items, so there is nothing for cmdk to filter client-side.