useDebouncedSearch - Admin Components

Note: This hook is available since Medusa v2.21.0.

The useDebouncedSearch hook manages a search input's value and exposes a debounced copy of it. The Medusa Admin uses it to avoid sending a request to the Medusa backend on every keystroke, such as in the useComboboxData hook.

Code
import { useDebouncedSearch } from "@medusajs/dashboard/hooks"

Example#

Bind searchValue to the input and use query in the request to the Medusa backend:

Code
1import { useDebouncedSearch } from "@medusajs/dashboard/hooks"2import { Input } from "@medusajs/ui"3import { useQuery } from "@tanstack/react-query"4import { sdk } from "../lib/sdk"5
6const ProductSearch = () => {7  const { searchValue, onSearchValueChange, query } =8    useDebouncedSearch()9
10  const { data } = useQuery({11    queryKey: ["products", query],12    queryFn: () => sdk.admin.product.list({ q: query }),13  })14
15  return (16    <Input17      value={searchValue}18      onChange={(e) => onSearchValueChange(e.target.value)}19      placeholder="Search products"20    />21  )22}

The hook updates query 300 milliseconds after the user stops typing, so the query only refetches once for a series of keystrokes.


Returns#

Loading...
Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵