Skip to content

Repository files navigation

React hooks to interact with StateBacked.dev machine instances

GitHub licensenpm versionCIDocs

StateBacked.dev runs state machines as your secure, scalable, serverless backend.

Check out the full State Backed docs for more detailed information and to launch your own state machine backend in just a few minutes.

You can use these React hooks to easily connect your UI to any of your real-time, persistent machine intances running in the State Backed cloud.

Installation

npm install --save @statebacked/react @statebacked/client

Example

import{StateBackedClient}from"@statebacked/client";import{useStateBackedMachine}from"@statebacked/react";import{useActor}from"@xstate/react";constclient=newStateBackedClient({anonymous: {orgId: "org-YOUR_ORG_ID",}});functionMyReactComponent(){const{ actor }=useStateBackedMachine(client,{// name of a machine you created via the smply CLI or StateBacked.devmachineName: "your-machine-name",// name of a machine instance to connect to or create// you can create as many instances of each machine as you'd likeinstanceName: "your-instance",// function to provide the initial context if we have to create the machine instancegetInitialContext(){return{any: "initialContextForYourMachine"}}});const[state,send]=useActor(actor);// now you can interact with your persistent, real-time, multi-player// State Backed machine instance just like it was a local state machine// send({ type: "any-event", extra: "data" })// render your UI based on the current machine state}

About

React hooks for interacting with the State Backed backend as a service

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages