useBackup
useBackup(
options:object):UseBackupResult
Defined in: src/react/useBackup.ts:121
Unified React hook for backup and restore functionality.
This hook provides methods to backup conversations to iCloud and restore them. It handles all the logic for checking timestamps, skipping unchanged files, authentication, and managing the backup/restore process.
Must be used within a BackupAuthProvider.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
|
|
|
WatermelonDB database instance |
|
|
( |
Export a conversation to an encrypted blob |
|
|
( |
Import a conversation from an encrypted blob |
|
|
( |
Request encryption key for the user address |
|
|
|
Current user address (null if not signed in) |
Returns
Example
import { useBackup } from "@anuma/sdk/react";
function BackupManager() {
const { icloud, hasAnyProvider } = useBackup({
database,
userAddress,
requestEncryptionKey,
exportConversation,
importConversation,
});
if (!hasAnyProvider) {
return <p>No backup providers configured</p>;
}
return icloud.isAuthenticated ? (
<>
<button onClick={() => icloud.backup()}>Backup</button>
<button onClick={() => icloud.restore()}>Restore</button>
<button onClick={icloud.disconnect}>Disconnect</button>
</>
) : (
<button onClick={icloud.connect}>Connect iCloud</button>
);
}