useDatabaseManager
useDatabaseManager(
walletAddress:string|undefined,manager:DatabaseManager):Database
Defined in: src/react/useDatabaseManager.ts:49
React hook that returns the correct WatermelonDB Database instance for the current wallet address.
Replaces the common pattern of:
const database = useMemo(() => getWatermelonDatabase(walletAddress), [walletAddress]);When the wallet address changes, a new database instance is returned, providing complete per-wallet data isolation.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
|
|
The current user’s wallet address, or undefined for guest mode |
|
|
A DatabaseManager instance (should be created once at app level) |
Returns
Database
The WatermelonDB Database instance for the current wallet
Example
import { useDatabaseManager, DatabaseManager, webPlatformStorage } from '@reverbia/sdk/react';
import LokiJSAdapter from '@nozbe/watermelondb/adapters/lokijs';
// Create once at app level
const dbManager = new DatabaseManager({
dbNamePrefix: 'my-app',
createAdapter: (dbName, schema, migrations) => new LokiJSAdapter({
schema, migrations, dbName,
useWebWorker: false,
useIncrementalIndexedDB: true,
}),
storage: webPlatformStorage,
onDestructiveMigration: () => window.location.reload(),
});
function MyComponent() {
const { user } = usePrivy();
const database = useDatabaseManager(user?.wallet?.address, dbManager);
// Pass database to SDK hooks
const { sendMessage } = useChatStorage({ database, ... });
}Last updated on