React
useSearch
useSearch is a stateless hook for one-shot queries. Unlike useQuery, it does not track a conversationId — each call is independent.
When to Use
| Hook | Use Case |
|---|---|
useQuery | Chat interfaces, multi-turn conversations |
useSearch | Search bars, FAQ lookups, single-question interfaces |
Usage
import { useSearch } from '@ilana/react';
function SearchBar() {
const { query, data, isLoading, error } = useSearch();
const handleSearch = async (term: string) => {
await query(term);
};
return (
<div>
<input
type="text"
placeholder="Search..."
onKeyDown={(e) => {
if (e.key === 'Enter') handleSearch(e.currentTarget.value);
}}
/>
{isLoading && <p>Searching...</p>}
{data && <p>{data.response}</p>}
{error && <p>Error: {error.message}</p>}
</div>
);
}API
The API is identical to useQuery:
const result = useSearch(options?: UseQueryOptions);Options
| Property | Type | Description |
|---|---|---|
onSuccess | (data: QueryOutput) => void | Called after a successful query |
onError | (error: IlanaError) => void | Called when a query fails |
Return Value
| Property | Type | Description |
|---|---|---|
query | (input: string) => Promise<QueryOutput | null> | Send a query |
isLoading | boolean | Whether a query is in progress |
data | QueryOutput | null | Last successful response |
error | IlanaError | null | Last error |
reset | () => void | Clear state |
The key difference from useQuery is that useSearch does not pass a conversationId — every call starts a fresh context with no memory of previous messages.