Skip to content

Interface: PlayRouterProviderBaseProps<TRouter, TActor, TNode>

API / @xmachines/play-router / index / PlayRouterProviderBaseProps

Defined in: packages/play-router/src/provider-lifecycle.ts:36

The props that every PlayRouterProvider of a framework shares.

TNode is what the framework renders: ReactNode for React, JSX.Element for Solid. It is the ONLY thing in these props that a framework decides, which is why they live here and not in an adapter.

An adapter re-exports a two-parameter alias of this type, with TRouter bound to the type of its router instance and TNode bound to its own node type.

Type Parameters

Type Parameter
TRouter
TActor extends RoutableActor
TNode

Properties

PropertyTypeDescriptionDefined in
actorTActorThe actor to keep in step with the router. It must be a stable reference: give the same actor instance on every render. An actor in the JSX, or a new actor on each render, makes the bridge disconnect and connect again each time.packages/play-router/src/provider-lifecycle.ts:42
basePath?stringMounts the routes of the machine under a URL prefix that the host owns, so that the routes of the host and the routes of the machine share one router. actor, router, and routeMap each need a stable reference. This prop needs none, and it rebuilds the bridge never: a change moves the live bridge with setBasePath(), so a host route that renders again with a new prefix keeps the actor, the route map, and its cache. The prefix says WHERE an actor is mounted, and never WHICH actor is mounted. An actor never changes identity, so a prefix segment that IDENTIFIES the actor gives a different actor prop instead, and THAT rebuilds the bridge — which is correct, because one actor takes one bridge. A location outside the prefix belongs completely to the host: the bridge sends no event there, and it corrects no URL there. Every :param needs a value. An unresolved one throws a MissingBasePathParamError out of the mount effect, because the bridge writes no URL without it. Render this component only after the host holds the value, which a route loader or a useParams() call does already.packages/play-router/src/provider-lifecycle.ts:80
basePathParams?Record<string, string | number>The values of the :param segments of PlayRouterProviderBaseProps.basePath, for example { machineId } for basePath="/:machineId/play". An inline object literal is correct here: the provider compares this prop by value, and a move to the same prefix does nothing.packages/play-router/src/provider-lifecycle.ts:89
renderer(actor, router) => TNodeThe renderer callback receives the same concrete actor type as the prop.packages/play-router/src/provider-lifecycle.ts:91
routeMapRouteMapThe route map of both directions, for the lookup between a state ID and a URL path. It must be a stable reference. The provider builds the bridge again on each change of the identity of routeMap. A value in the JSX, for example createRouteMapFromTree(routeTree), makes a new object on every render, and the bridge therefore connects again on every render. Hold the value with useMemo: const routeMap = useMemo(() => createRouteMapFromTree(routeTree), [routeTree]);packages/play-router/src/provider-lifecycle.ts:57
routerTRouterThe router instance that the bridge keeps in step with the actor. It must be a stable reference.packages/play-router/src/provider-lifecycle.ts:44