Skip to content

React

React SDK for building Probability plugins. Plugins are web apps that can help with gameplay, act as an AI opponent, manage decks, enforce rules, etc.

A plugin is launched via a URL hash carrying a HashProps object. Once mounted, <ProbProvider> connects to the sync server; useProbDocument handles the game state and usePresenceState broadcasts presence.

A working example lives at examples/example-plugin — see its README for run/launch instructions.

  1. Invalid URL hash: parseHashProps() returned undefined; consumer should render a fallback.
  2. Automerge sync: doc never loads (~60s timeout). WebSocket errors are silent.
  3. changeDoc(): doc schema validation failed
  4. useProbDocument: document deleted by peer
  5. Doc update: invalid mutation (eg undefined, non-serializable values)
  6. Peer presence: Warning: peer broadcasted an invalid presence state. Currently silent — TODO.
  7. update(): local presence schema validation failed

SDK for building probability.nz plugins (React).

Defined in: react/ProbProvider.tsx:8

children: ReactNode

Defined in: react/ProbProvider.tsx:11

optional sync: string[]

Defined in: react/ProbProvider.tsx:10

WebSocket sync server URLs.


ProbProvider(__namedParameters): Element

Defined in: react/ProbProvider.tsx:18

Wrap your plugin to enable document sync and SDK hooks.

ProbProviderProps

Element


useHashProps(): HashProps | undefined

Defined in: react/useHashProps.ts:19

Parsed HashProps from location.hash, reactive to hashchange. Returns undefined if the hash is missing or unparseable.

HashProps | undefined


useProbDocument<T>(id): [Doc<T>, ChangeDocFn<T>]

Defined in: react/useProbDocument.ts:16

Schema-validated access to the shared game document.

T extends object

AnyDocumentId

[Doc<T>, ChangeDocFn<T>]

On schema validation failure.

Suspends until loaded.

usePresenceState<T>(docUrl, __namedParameters): object

Defined in: react/usePresenceState.ts:29

Share ephemeral state with peers (e.g. cursors, intended moves).

T extends PresenceState

AnyDocumentId

UsePresenceStateOptions<T>

object

localState: Store<T>

peerStates: PeerStateView<T>

update: (updater) => void

(prev) => T

void

tickRate — DEFAULT_TICK_RATE

On schema validation failure.

Suspends until loaded.

createGame(repo, manifest, scenarioIndex): DocHandle<GameState>

Defined in: createGame.ts:10

Create a new game document from a manifest and scenario index.

Repo

GameManifest

number

DocHandle<GameState>

If scenarioIndex is out of bounds.

buildGameState for building state without creating a document.