/** * useFeltDB - React hook for FeltDB integration * * This module provides React hooks for easily integrating FeltDB * into React applications with automatic state management. * * Usage: * ```jsx * import { useFeltDB } from './hooks/useFeltDB'; * * function UserList() { * const users = useFeltDB("users"); * * const addUser = (name, email) => { * users.insert(name, email); * }; * * return ( *
* {users.records.map(user => ( *
{user.name}
* ))} *
* ); * } * ``` */ import type { JsDb } from '@feltdb/core/wasm'; import type { Collection } from '@feltdb/core'; interface UseFeltDBOptions { /** Auto-refresh interval in milliseconds (0 to disable) */ refreshInterval?: number; /** Callback when data updates */ onUpdate?: (records: any[]) => void; /** Callback when error occurs */ onError?: (error: string) => void; } interface UseFeltDBResult { /** Array of records from the database */ records: T[]; /** Whether data is loading */ loading: boolean; /** Error message if any */ error: string | null; /** Insert a new record */ insert: (key: string, data: Record) => boolean; /** Get a single record by key */ get: (key: string) => any | null; /** Refresh data manually */ refresh: () => void; /** Update a record */ update: (id: string | number, changes: Partial) => Promise; /** Delete a record */ delete: (id: string | number) => Promise; } /** * React hook for FeltDB state-first collections * * This is a thin adapter that bridges React state management with FeltDB's * unified state model. All applications (React, Vue, Svelte) use the same * underlying Collection semantics. * * @param collection A FeltDB Collection (live application state) * @param options Configuration options * @returns UseFeltDBResult with records and helper methods * * @example * ```jsx * import { useFeltDB } from 'feltdb/useFeltDB'; * * function UserList({ collection }) { * const { records, loading, error, insert, update } = useFeltDB(collection); * * if (loading) return
Loading...
; * if (error) return
Error: {error}
; * * return ( *
* {records.map((user) => ( *
{user.name}
* ))} *
* ); * } * ``` */ export declare function useFeltDB(collection: Collection | null, options?: UseFeltDBOptions): UseFeltDBResult; /** * Legacy compatibility: React hook for FeltDB capability queries * Uses the low-level JsDb API for backward compatibility. * * New code should use useFeltDB with Collections instead. */ export declare function useLegacyFeltDB(db: JsDb | null, capability: string, options?: UseFeltDBOptions): UseFeltDBResult; /** * Higher-order component for wrapping components with FeltDB * * @param Component React component that receives db and useFeltDB hook * @param dbPath Path to the database file * @returns Wrapped component * * @example * ```jsx * const UserListWithDb = withFeltDB(UserList, "app.db"); * ``` */ export declare function withFeltDB

(Component: React.ComponentType

, dbPath: string): React.FC

; /** * Example component using useFeltDB * * @example * ```jsx * import { useFeltDB } from './hooks/useFeltDB'; * * function UserList({ db }) { * const { records, loading, error, insert } = useFeltDB(db, "users", { * refreshInterval: 5000, // Refresh every 5 seconds * }); * * if (loading) return

Loading...
; * if (error) return
Error: {error}
; * * return ( *
* {records.map((user: any) => ( *
{user.name} ({user.email})
* ))} *
* ); * } * ``` */ export default useFeltDB; //# sourceMappingURL=useFeltDB.d.ts.map