Skip to content

Hooks Overview

HookWhen to use itReturns
useQueryList or find nodes. Read-only.{ data, loading, error, reload }
useMutateCreate, update, delete nodes.{ create, update, remove, restore, mutate }
useNodeEdit a single node with collaborative rich text.{ data, doc, update, syncStatus, remoteUsers, ... }
  • Listing data (tables, lists, grids, search results) — useQuery
  • Reading a single node by ID (detail views, cards) — useQuery(schema, id)
  • Creating or deletinguseMutate
  • Updating properties on a detail page — useMutate().update or useNode().update
  • Rich text editing (TipTap, collaborative docs) — useNode (gives you a Y.Doc)
  • Showing who’s online (presence, cursors) — useNode (gives you remoteUsers and awareness)
Do you need a Yjs document (rich text, canvas)?
├── Yes → useNode
└── No
├── Reading data? → useQuery
└── Writing data? → useMutate

useNode is the only hook that manages a Yjs document and P2P sync connection. If you don’t need collaborative editing, useQuery + useMutate are simpler and more efficient.

HookPurpose
useIdentityGet the current user’s DID and auth status
useCommentsThread-based comments on any node
useHistoryChange history for a node
useUndoUndo/redo for node changes

Every hook reads from a React context provided by XNetProvider. If you call a hook outside the provider, it throws:

import { XNetProvider } from '@xnet/react'
function App() {
return (
<XNetProvider config={{ authorDID, signingKey }}>
{/* All hooks work inside here */}
<TaskList />
</XNetProvider>
)
}
React Component
├── useQuery(TaskSchema, filter)
│ └── NodeStore.list() → IndexedDB
│ └── subscribes to NodeChangeEvents
├── useMutate()
│ └── NodeStore.create/update/delete()
│ ├── validates against schema
│ ├── signs change (Ed25519)
│ ├── persists to IndexedDB
│ ├── emits NodeChangeEvent → useQuery re-renders
│ └── syncs to peers (via SyncManager)
└── useNode(PageSchema, id)
├── NodeStore (structured properties)
└── Y.Doc (rich text)
├── WebRTC sync (via SyncManager or WebSocketSyncProvider)
├── debounced persistence to IndexedDB
└── awareness (remote users, cursors)