Skip to content

Interface: PlayRouterProviderProps<TActor>

API / @xmachines/play-react-router / PlayRouterProviderProps

Defined in: play-react-router/src/play-router-provider.tsx:27

The props of the PlayRouterProvider of React Router.

router is the React Router instance that createBrowserRouter returns. PlayRouterProviderBaseProps holds the requirement of a stable reference for actor, for router, and for routeMap.

Extends

Type Parameters

Type ParameterDefault type
TActor extends RoutableActorRoutableActor

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
actorpublicTActorThe 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.PlayRouterProviderBaseProps.actorplay-router/src/provider-lifecycle.ts:46
basePath?publicstringMounts 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.PlayRouterProviderBaseProps.basePathplay-router/src/provider-lifecycle.ts:84
basePathParams?publicRecord<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.PlayRouterProviderBaseProps.basePathParamsplay-router/src/provider-lifecycle.ts:93
compiledCache?readonlyKeyValueCache<URLPatternLike>The cache of the COMPILED URLPattern, which is what this function returns. The default is a cache that this module shares with every caller of the process. Pass one to give a tenant or a request a compilation that no other evicts, and pass { get: () => undefined, set: () => {} } to compile each time. A caller that passes patternCache for isolation passes this one too. The compiled cache is read FIRST, so a hit on it answers before the parse runs at all — a passed parse cache alone therefore isolates nothing once another caller has compiled the same pattern.PlayRouterProviderBaseProps.compiledCacheplay-url/src/url-pattern-utils.ts:119
patternCache?readonlyKeyValueCache<ParsedPattern>The cache of the PARSE of a pattern. The default is the cache that this package shares with every caller of the process.PlayRouterProviderBaseProps.patternCacheplay-pattern/src/cache.ts:41
rendererpublic(actor, router) => ReactNodeThe renderer callback receives the same concrete actor type as the prop.PlayRouterProviderBaseProps.rendererplay-router/src/provider-lifecycle.ts:95
routeMappublicRouteMapThe 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]);PlayRouterProviderBaseProps.routeMapplay-router/src/provider-lifecycle.ts:61
routerpublicRouterThe router instance that the bridge keeps in step with the actor. It must be a stable reference.PlayRouterProviderBaseProps.routerplay-router/src/provider-lifecycle.ts:48