Skip to content
Logo

Solid

@ghostry/finity-solidjs builds finity on Solid's signals and effects.

import { initialize } from "@ghostry/finity-solidjs";
 
export const finity = initialize({});

Despite their names, finity's functions aren't hooks with rules in Solid. They create signals and effects, so call them where you'd call createSignal and createEffect: in a component body, or another reactive owner.

State

useStrictlyTransitionalState and useTransitionalState keep the state in a signal. state.value is that signal's getter, so reading state.value() in JSX or an effect tracks it.

Effects

Prefer a component per state, rendered from useRender. A case runs once when its state starts, so the component body starts the state's work, and onCleanup stops it when the state ends. See Effects.

finity's useEffect runs the matching case in a createEffect that reads the state, so it runs once when created, and again whenever the state changes.

Rendering

useRender renders through Solid's Switch and Match, so changing cases replaces only what the case rendered.

A case runs once when its states start matching, like a component, and the state it receives updates in place while the case still matches. Read its properties in JSX or another reactive scope, and don't destructure them in the case's parameters:

  return 
    .(.)
    .(["Uploading"], () => < ={.} />)
    .(["Done"], () => < ={.}>Download</>)
    .();

A transition from Uploading to Uploading updates progress without calling the case again. Once the state leaves a case's kinds, the state that case holds keeps its last values, so a transition taken from it afterwards is refused as stale.

A case may return a function instead of JSX, which Solid renders reactively:

.case(["Uploading"], (uploading) => () => `${uploading.progress}%`)

JSX.Element includes undefined in Solid, so a switch on kind doesn't check that every state is handled. Use useRender. See Rendering.