Skip to main content
Learn how to implement real-time search and autocomplete functionality with Sonamu’s Search Input component.

Search Input Overview

Real-time Search

Search while typing Immediate results

Autocomplete

Suggested search terms Quick selection

Debounce

API call optimization Remove unnecessary requests

Highlighting

Search term emphasis Improved readability

What is Search Input?

The basic HTML <input type="search"> requires clicking a search button to execute the search.
Problems:
  1. Button click required: Need to press enter or button to search
  2. Delayed feedback: Need to execute search to see results
  3. No autocomplete: User has to type everything
  4. Hard to fix typos: Can’t discover typos until seeing results

Solution: Search Input Component

Sonamu’s Search Input provides real-time search while typing and autocomplete.
Benefits:
  1. Immediate feedback: See results while typing
  2. Autocomplete: Quick input with suggested search terms
  3. Debounce: Minimize unnecessary API calls
  4. Keyboard navigation: Select suggestions with arrow keys

Basic Usage

The most basic search functionality.

With Autocomplete

Display suggestion items.

Integration with Service

Search using Sonamu Service.

Advanced Features

Search specific entities.

Integration with Filters

Apply filters along with search terms.

Search History

Save and display recent search terms.

Highlighting

Highlight search terms in results.

Custom Hook Patterns

useSearch Hook

Abstract search logic into a reusable Hook.
Usage:

useSearchSuggestions Hook

Manage autocomplete suggestions.

Practical Examples

Search across the entire site.
Search integrated in header.

Performance Optimization

Debounce Optimization

Adjust debounce time according to search frequency.

Caching Strategy

Cache search results with TanStack Query.

Request Cancellation

Cancel ongoing requests when component unmounts.

Cautions

Cautions when using Search Input: 1. Debounce required: 300~500ms recommended 2. Set minimum search length (usually 2-3 characters) 3. Handle empty string: Prevent returning all results 4. Support keyboard navigation (accessibility) 5. Search API requires index optimization 6. Consider pagination for many results

Next Steps

ID Async Select

Relational data selection

Custom Components

Component customization

View Scaffolding

Auto view generation

TanStack Query Hook

Data caching