Skip to content
aq-ui
Back to HooksHook

Use Typeahead

Open-code aq-ui React hook for Use Typeahead.

Installation

pnpm dlx aq-ui@alpha add use-typeahead

API reference

Client module

Import the parts you need, then jump to an export for its contract.

View full source

Quick start

"use client"

import { useTypeahead } from "@/hooks/use-typeahead"

TypeaheadControls

interfaceSource L17

Type contract for TypeaheadControls.

interface TypeaheadControls

Members

NameType
search(character: string) => number
onKeyDown(event: React.KeyboardEvent) => void
reset() => void

useTypeahead

functionSource L23

Open-code aq-ui React hook for Use Typeahead.

function useTypeahead<T>({ items, activeIndex, onActiveIndexChange, getTextValue = (item) => String(item), timeout = 500, loop = true, disabledIndices = [], }: UseTypeaheadOptions<T>): TypeaheadControls
Returns
TypeaheadControls

Parameters

NameType
optionsUseTypeaheadOptions<T>

UseTypeaheadOptions

interfaceSource L7

Type contract for UseTypeaheadOptions.

interface UseTypeaheadOptions<T>

Members

NameTypeDefault
itemsT[]—
activeIndexnumber—
onActiveIndexChange(index: number) => void—
getTextValue?(item: T) => string(item) => String(item)
timeout?number500
loop?booleantrue
disabledIndices?Iterable<number>[]

Registry dependencies

use-stable-callback

Files

  • hooks/use-typeahead.ts

Source