Skip to content

Client

Installation

sh
npm i @rouage/client

This is an ESM-only package. Type definitions are included.

Configuration

ts
import { SyncEngine } from '@rouage/client'

const syncEngine = new SyncEngine({
  roomId: 'account123',
})

Data Fetching

ts
async function fetchPosts() {
  const response = await fetch('https://jsonplaceholder.org/posts')
  return response.json() as unknown as Post[]
}
ts
const syncQuery = syncEngine.createQuery({
  queryKey: ['posts'],
  queryCall: fetchPosts,
})

Subscription

ts
syncQuery.subscribe(posts => console.log(posts))
ts
syncQuery.unsubscribe()

Invalidation

ts
syncEngine.invalidate({ queryKey: ['posts'] })