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
import { useDebouncedSearch } from "@medusajs/dashboard/hooks"
import { Input } from "@medusajs/ui"
import { useQuery } from "@tanstack/react-query"
import { sdk } from "../lib/sdk"

const ProductSearch = () => {
  const { searchValue, onSearchValueChange, query } =
    useDebouncedSearch()

  const { data } = useQuery({
    queryKey: ["products", query],
    queryFn: () => sdk.admin.product.list({ q: query }),
  })

  return (
    <Input
      value={searchValue}
      onChange={(e) => onSearchValueChange(e.target.value)}
      placeholder="Search products"
    />
  )
}

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
⇧↵