dexie-react-hooks provides a collection of React hooks designed for seamlessly integrating Dexie.js, a wrapper for IndexedDB, into React applications. It facilitates reactive data fetching and real-time updates directly from the IndexedDB database, abstracting away the complexities of manual subscription management. The current stable version is 4.4.0, aligning with the broader Dexie.js ecosystem releases. The package follows a release cadence tied closely to the main Dexie.js library, with frequent updates addressing bug fixes and new features, such as enhanced Y.js integration and Dexie Cloud capabilities. Its key differentiators include simplifying reactive state management with IndexedDB, offering idiomatic React patterns for database interactions, and ensuring components re-render automatically when underlying data changes.
npm install dexie-react-hooksVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to define a Dexie database, create a React component, and use `useLiveQuery` to fetch and display data reactively, with add and toggle functionality.
For Y.js integration, ensure `npm install y-dexie` and update `DexieYProvider` imports from `y-dexie` instead of `dexie`.
Always check your `dexie` and `react` versions and ensure they fall within the specified peer dependency ranges. Use `npm install` or `yarn install` to resolve peer dependencies automatically if your package manager supports it, or manually install compatible versions.
Always use Dexie's API methods for all database modifications. If you need to interact with IndexedDB directly, consider manually triggering a re-render or explicitly notifying `useLiveQuery` if possible.
Review the variables used inside your `useLiveQuery` callback function. If any props or state variables are used, include them in the dependency array to ensure the query re-runs when those values change.
Ensure the package is installed with `npm install dexie-react-hooks dexie react react-dom`. Use `import { useLiveQuery } from 'dexie-react-hooks'` in an ESM-compatible environment, or configure your build system for CJS compatibility.Ensure all database modifications (add, put, delete, update) are done via Dexie's API. Check that your `dexie` package version is `>=4.0.9`. Verify the `useLiveQuery` dependency array includes all external variables used within the query function.
Review your Dexie database schema definition, ensuring tables are correctly defined in `db.version().stores({})` and that the `db` instance is correctly created. For TypeScript, ensure proper typing for your database and its tables.