Hooks

Headless hook for complete control.


useSearch

Build your own search UI with the useSearch hook:

import { useSearch } from "@etoile-dev/react";

export default function MySearch() {
const { query, setQuery, results, isLoading } = useSearch({
  apiKey: process.env.NEXT_PUBLIC_ETOILE_PUBLIC_KEY,
  collections: ["paintings"],
});

return (
  <div>
    <input
      value={query}
      onChange={(e) => setQuery(e.target.value)}
      placeholder="Search..."
    />
    {isLoading && <p>Loading...</p>}
    <ul>
      {results.map((result) => (
        <li key={result.external_id}>{result.title}</li>
      ))}
    </ul>
  </div>
);
}

Options

ParameterTypeDescription
apiKeyrequiredstringYour API key.
collectionsrequiredstring[]Collections to search.
limitnumberMax results (default: 10).
debounceMsnumberDebounce delay (default: 100).

Returns

ParameterTypeDescription
querystringCurrent search query.
setQuery(q: string) => voidUpdate the query.
resultsSearchResultData[]Search results.
isLoadingbooleanTrue while fetching.
selectedIndexnumberActive result index.
setSelectedIndex(i: number) => voidUpdate selection.
clear() => voidClear query and results.

Related

  • Setup — drop-in and primitives
  • Styling — theme or custom UI