Registry / database / react-data-storage-sqlite-hook

react-data-storage-sqlite-hook

JSON →
library3.0.2jsnpmunverified

React hook wrapping the capacitor-data-storage-sqlite plugin to provide a simple key-value store with SQLite persistence for Capacitor 5 apps. Version 3.0.2 is current; it requires @capacitor/core ^5.0.0 and react ^18.0.0. The hook exposes functions like setItem, getItem, getAllKeys, and JSON import/export, running natively on iOS, Android, and the web. Unlike generic storage hooks, this one leverages Capacitor's SQLite plugin for structured data operations including table management and filtering. Low download counts and single maintainer indicate limited community adoption.

npm install react-data-storage-sqlite-hook
INSTALL
IMPORT
SIG · REACT-DATA-STORAGE
R
react-data-storage-sqlite-hook
databasejavascriptv3.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useStorageSQLite
import { useStorageSQLite } from 'react-data-storage-sqlite-hook'
import useStorageSQLite from 'react-data-storage-sqlite-hook'
This is a named export, not a default export. Common mistake: trying default import.
useEffect
import { useEffect } from 'react'
The hook is typically used inside a useEffect or event handler for async operations.
Dialog
import { Dialog } from '@capacitor/dialog'
import { Dialog } from 'react-data-storage-sqlite-hook'
Dialog is from @capacitor/dialog, not this package. Confusing because the example uses it.

Shows opening a store, setting and getting an item, then closing the store inside useEffect.

import { useStorageSQLite } from 'react-data-storage-sqlite-hook'; import { useEffect } from 'react'; function App() { const { openStore, setItem, getItem, closeStore } = useStorageSQLite(); useEffect(() => { (async () => { try { await openStore({}); await setItem('greeting', 'Hello SQLite!'); const value = await getItem('greeting'); console.log(value); // 'Hello SQLite!' await closeStore(); } catch (e) { console.error(e); } })(); }, []); return <div>Check console</div>; } export default App;
Debug
Known issues
breakingopenStore must be called before any read/write operations or they will fail silently or throw.
fix
Ensure openStore() is awaited before calling setItem, getItem, etc.
affects: >=3.0.0
gotchaAll hook methods are async; forgetting to await them will cause timing issues (undefined returns, unhandled promises).
fix
Always use await inside async functions (e.g., event handlers, useEffect async wrappers).
affects: >=1.0.0
deprecatedThe closeStore() method may not be needed in recent versions; it might be automatically handled. Deprecated in some Capacitor SQLite plugins.
fix
Check documentation; prefer omitting closeStore() if the store lifecycle is automatic.
affects: <3.0.0
gotchaThe hook is designed for Capacitor 5 only; not compatible with Capacitor 3/4 without migration.
fix
Use version 2.x for Capacitor 4, or upgrade your project to Capacitor 5.
affects: >=3.0.0
breakingsetItem and getItem only work for string values; objects/arrays must be JSON.stringify/parse manually.
fix
Use JSON.stringify before setItem and JSON.parse after getItem for non-string data.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'call')
Called useStorageSQLite() outside of a React component or before Capacitor is ready.
fix
Ensure the hook is used inside a React functional component and Capacitor.isNativePlatform() checks if needed.
Error: Store is not open. Call openStore() first.
Attempted to use getItem/setItem before awaiting openStore().
fix
Move openStore() call to the top of your async function and await it before other operations.
TypeError: plugin is not a function
Installed only the hook but forgot to install the native plugin 'capacitor-data-storage-sqlite'.
fix
Run: npm install capacitor-data-storage-sqlite (the peer dependency).
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies
@capacitor/corerequiredRequired peer dependency for Capacitor platform APIs
Agent activity
17 hits · last 30 days
node
16
Resources
react-data-storage-sqlite-hook — npm install react-data-storage-sqlite-hook · libregistry