SSE Hooks

useSearchWithSuggestions

GitHub
A comprehensive hook for building "Command Palette" or "Omnibar" style search interfaces. * It provides "Ghost Text" autocomplete (like Google search), command scoping (like Slack's / commands), and keyboard support. It handles the complex logic of parsing input strings to separate commands from queries.

Installation

npx sse-hooks add use-search-with-suggestions

Usage

example.ts
import { useSearchWithSuggestions } from "./{hooks file}";

const users = [
  { id: 1, name: "Alice", role: "admin" },
  { id: 2, name: "Bob", role: "user" },
];
const { inputProps, ghostText, filteredData, isSuggestionAvailable } =
  useSearchWithSuggestions(
    users,
    ["name"], // Default search key
    {
      commands: [
        // Typing ":role admin" will filter by role
        { trigger: "role", scope: "role" },
        // Typing ":admins" will run a custom filter function
        { trigger: "admins", filter: (u) => u.role === "admin" },
      ],
    },
  );
return (
  <div className="search-container">
    <div className="input-wrapper relative">
      // Ghost Layout
      <input
        className="absolute text-gray-300 bg-transparent pointer-events-none"
        value={ghostText}
        readOnly
      />
      // The Actual Input
      <input className="relative bg-transparent" {...inputProps} />
    </div>
    <ul>
      {filteredData.map((u) => (
        <li key={u.id}>{u.name}</li>
      ))}
    </ul>
  </div>
);

API

Parameters

Prop Default Type
data-

T[]

The array of data objects to search through.

searchKeys-

any

An array of keys (e.g., ['name', 'email']) to search against by default.

config-

BaseSearchConfig<T>

Optional configuration object.

Returns

Return Value Default Type
return-

UseSearchSuggestionsResult<T>

Hook return value

Types Aliases

No specific type aliases defined for this component.

Changelog

2b25b — feat: add useSearchWithSuggestions hook for enhanced search functionality

Built with Love • © 2026