Skip to content
Homeostate

TanStack Store

@homeostate/store-tanstack

TanStack Store adapter for @homeostate/core

@homeostate/store-tanstack@0.1.1npmSource
Warning

Early release. The API is still being designed and may change in any 0.x minor version.

TanStack Store adapter for @homeostate/core. It keeps a TanStack Store in sync with a CRDT backend such as @homeostate/crdt-yjs, @homeostate/crdt-loro, or @homeostate/crdt-automerge.

Install

npm install @homeostate/core @homeostate/store-tanstack @tanstack/store @homeostate/crdt-yjs yjs

@tanstack/store 0.11 is a peer dependency.

Usage

import * as Y from "yjs";
import { createStore } from "@tanstack/store";
import { createSyncEngine } from "@homeostate/core";
import { createYjsBackend } from "@homeostate/crdt-yjs";
import { createTanStackStoreAdapter } from "@homeostate/store-tanstack";

const store = createStore({ count: 0 });

const engine = createSyncEngine(
  createYjsBackend(new Y.Doc(), "shared"),
  createTanStackStoreAdapter(store),
);
engine.connect();

store.setState((state) => ({ ...state, count: state.count + 1 }));

Stores created with or without an actions factory both work; only the state is synced.