Skip to content

Function: usePlayView()

API / @xmachines/play-solid / usePlayView

function usePlayView(): ViewContextValue;

Defined in: packages/play-solid/src/ActorProvider.tsx:100

The hook that gives the current view context inside an ActorProvider tree.

Read a field where you use it, and destructure it not. spec is a GETTER: the provider keeps the subtree across an emission that holds the viewKey, and it publishes the new spec through that getter. const { spec } = usePlayView() therefore freezes at the first read, and the screen stops following the actor — with no error and no warning.

The context holds spec, handlers, registry and store, and no other field. The three beside spec are copied values, and the provider builds the subtree again when one of them changes — see ViewContextValue.

This changed in 2.3.0. Before it, every emission built the subtree again, so a value that a component read one time was fresh because the component itself was new.

Returns

ViewContextValue

Throws

When the caller is outside an ActorProvider tree or a PlayUIProvider tree

Example

import { usePlayView } from "@xmachines/play-solid";
const MyRenderer: Component = () => {
const view = usePlayView();
return <Renderer spec={view.spec} registry={view.registry} />;
};