Client

Client-side implementation of DocSync

createDocSyncClient

Creates a DocSync client instance along with React hooks for document synchronization.

import { createDocSyncClient } from "@docukit/docsync-react";

const { client, useDoc, usePresence } = createDocSyncClient({
  docBinding,
  server: {
    url: "http://localhost:8080",
    auth: {
      getToken: async () => await fetchAuthToken(),
    },
  },
  local: {
    provider: IndexedDBProvider,
    getIdentity: async () => ({
      userId: "user-123",
      secret: await fetchUserSecret(),
    }),
  },
});

Props

Prop

Type

Returns

Prop

Type


useDoc

React hook that subscribes to a document with reactive state updates.

const result = useDoc({ type: "notes", id: "doc-123" });

const result = useDoc({ type: "notes", createIfMissing: true });

const result = useDoc({ type: "notes", id: "doc-123", createIfMissing: true });

Props

Prop

Type

Returns

Prop

Type


usePresence

React hook that subscribes to presence updates for a document and provides a setter function.

const [presence, setPresence] = usePresence({ docId: "doc-123" });

setPresence({ cursor: { x: 100, y: 200 }, color: "#ff0000" });

Props

Prop

Type

Returns

Prop

Type

On this page

Edit on GitHub