Skip to content

React hooks to get a realtime store for collections and current user

Notifications You must be signed in to change notification settings

ScalaeStudio/appwrite-hooks

Repository files navigation

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 (<>...</>)
}

About

React hooks to get a realtime store for collections and current user

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published