Ilana Docs
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

HookUse Case
useQueryChat interfaces, multi-turn conversations
useSearchSearch 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

PropertyTypeDescription
onSuccess(data: QueryOutput) => voidCalled after a successful query
onError(error: IlanaError) => voidCalled when a query fails

Return Value

PropertyTypeDescription
query(input: string) => Promise<QueryOutput | null>Send a query
isLoadingbooleanWhether a query is in progress
dataQueryOutput | nullLast successful response
errorIlanaError | nullLast error
reset() => voidClear 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.