Skip to content

clientDocument

const clientDocument: <TName, TType, TEncoded, TOptions>({ name, schema: valueSchema, ...inputOptions }) => ClientDocumentTableDef<TName, TType, TEncoded, Types.Simplify<WithDefaults<TOptions>>>

Defined in: packages/@livestore/common/dist/schema/state/sqlite/client-document-def.d.ts:20

Special:

  • Synced across client sessions (e.g. tabs) but not across different clients
  • Derived setters
    • Emits client-only events
    • Has implicit setter-reducers
  • Similar to React.useState (except it’s persisted)

Careful:

  • When changing the table definitions in a non-backwards compatible way, the state might be lost without explicit reducers to handle the old auto-generated events

TName extends string

TType

TEncoded

TOptions extends Input<NoInfer<TType>>

{ name, schema: valueSchema, …inputOptions }

Section titled “{ name, schema: valueSchema, …inputOptions }”

object & TOptions

ClientDocumentTableDef<TName, TType, TEncoded, Types.Simplify<WithDefaults<TOptions>>>