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
| Parameter | Type | Description |
|---|---|---|
apiKeyrequired | string | Your API key. |
collectionsrequired | string[] | Collections to search. |
limit | number | Max results (default: 10). |
debounceMs | number | Debounce delay (default: 100). |
Returns
| Parameter | Type | Description |
|---|---|---|
query | string | Current search query. |
setQuery | (q: string) => void | Update the query. |
results | SearchResultData[] | Search results. |
isLoading | boolean | True while fetching. |
selectedIndex | number | Active result index. |
setSelectedIndex | (i: number) => void | Update selection. |
clear | () => void | Clear query and results. |