Skip to content

Latest commit

 

History

History
45 lines (35 loc) · 1.03 KB

ReadMe.md

File metadata and controls

45 lines (35 loc) · 1.03 KB

Appwrite React hooks

Realtime stores synced with Appwrite collections and user.

Installation

yarn add https://github.com/ScalaeStudio/appwrite-hooks

Usage

import { useUser, useCollection } from 'appwrite-hooks'
import { Client, Databases, Account } from 'appwrite'

// Ideally do that in a separate module
const appwriteClient = new Client()
const appwriteDatabase = new Databases(appwriteClient)
const appwriteAccount = new Account(appwriteClient)
client
    .setEndpoint('http://your-appwrite-instance/v1')
    .setProject('your-project')

function YourComponent() {
    const { account, loaded, error } = useUser(appwriteClient, appwriteAccount)
    const { documents, loaded, error } = useCollection(
        appwriteClient,
        appwriteDatabase,
        "database-id",
        "collection-id",
    )
    const { document, loaded, error } = useDocument(
        appwriteClient,
        appwriteDatabase,
        "database-id",
        "collection-id",
        "document-id",
    );

    return (<>...</>)
}