robot-solid
v0.4.0
Published
Robot3 integration for solid using robot-hooks
Downloads
21
Readme
robot-solid
Robot3 integration for solid using robot-hooks
Quick start
Install it:
npm i robot-solid
# or
yarn add robot-solid
# or
pnpm add robot-solid
Use it:
import { type Component } from 'solid-js';
import { createMachine, invoke, reduce, state, transition } from 'robot3';
import { useMachine } from 'robot-solid';
const machine = createMachine({
idle: state(
transition("click", "loading")
),
loading: invoke(async () => new Promise(resolve => setTimeout(() => resolve(["user1", "user5"]), 1000)),
transition("done", "loaded", reduce((ctx: any, ev:any) => ({ ...ctx, users: ev.data })))),
loaded: state()
}, () => ({users: []}))
const App: Component = () => {
const [current, send] = useMachine( machine, {users: []})
return (
<div>
<div>
{current()?.name}
</div>
<div>
{current()?.context.users?.join(", ")}
</div>
<button onClick={() => send("click")}>Load</button>
</div>
)
}