Skip to content

useSymbolSearch

Search and select a trading instrument. The hook debounces queries and cancels in-flight requests via AbortController on every keystroke and on unmount.

const {
query,
results,
isSearching,
activeSymbol,
setQuery,
selectSymbol,
clearResults,
} = useSymbolSearch(debounceMs);
ParameterTypeDefaultDescription
debounceMsnumber300Delay before calling datafeed.searchSymbols
FieldTypeDescription
querystringCurrent search query
resultsPartialSymbolInfo[]Results from the last search
isSearchingbooleantrue while the request is in flight
activeSymbolPartialSymbolInfo | nullCurrently selected symbol from state.symbol
setQuery(q: string) => voidUpdate the query (triggers debounced search)
selectSymbol(symbol: PartialSymbolInfo) => voidSelect a symbol — dispatches SET_SYMBOL
clearResults() => voidClear search results
const { query, results, isSearching, selectSymbol, setQuery } =
useSymbolSearch(300);
<input
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="Search…"
/>;
{isSearching && <Spinner />}
{results.map((sym) => (
<button key={sym.ticker} onClick={() => selectSymbol(sym)}>
{sym.ticker}
</button>
))}

The search itself is delegated to your Datafeed.searchSymbols implementation — forward the provided AbortSignal to fetch to cancel stale requests. searchSymbols is optional: when your datafeed does not implement it, the hook simply resolves every search to an empty result list.