Skip to main content
This example demonstrates a complete React + Vite application using the Quran Search Engine library with TypeScript.

Features

  • Real-time search with debounced input
  • Lemma, root, and fuzzy search options
  • Highlighted search results by match type
  • Pagination controls
  • Match statistics and scoring
  • TypeScript support

Setup

1

Install dependencies

2

Run the development server

From the workspace root:
Or from the example directory:
3

Open your browser

Navigate to http://localhost:5173

Project structure

Loading data

Load all required datasets on app initialization:
App.tsx
All data loaders return Promises and can be loaded in parallel using Promise.all() for optimal performance.

Search implementation

Implement debounced search with configurable options:
App.tsx
Use the useDebounce hook to avoid triggering searches on every keystroke, improving performance and user experience.

Debounce hook

The custom debounce hook delays state updates:
useDebounce.ts

Highlighting results

Render verses with highlighted matches using getHighlightRanges:
VerseItem.tsx
The getHighlightRanges function returns UI-agnostic highlight ranges. You control how to render them in your component, avoiding dangerouslySetInnerHTML.

Pagination

Implement pagination controls:
App.tsx

Display search statistics

Show match counts by type:
App.tsx

Dependencies

The example uses these key dependencies:
package.json
This example uses workspace:* for the library dependency because it’s part of a pnpm workspace. In your own project, use the npm package: "quran-search-engine": "^1.0.0"

Key features demonstrated

  • Type safety: Full TypeScript support with proper types for all API calls
  • Performance: Debounced search input and paginated results
  • User experience: Loading states, search options, and visual feedback
  • Highlighting: Match-type-specific highlighting using the getHighlightRanges utility
  • Extensibility: Clean component structure for easy customization