Skip to content

Function: createPlayRouterProvider()

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

function createPlayRouterProvider<TRouter>(BridgeCtor): <TActor>(__namedParameters) => Element;

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

Creates a React PlayRouterProvider component of one bridge class.

The component of the return value connects a PlayerActor to the framework router. It keeps the actor state and the browser URL in step, in both directions.

The component creates the bridge one time, on mount, and it disconnects the bridge on unmount. It also builds the bridge again on a change of the identity of actor, of router, or of routeMap. Therefore all three props must be stable references: create them outside the JSX, or hold them with useMemo. Under the React <StrictMode>, the effect runs two times on mount (connect, disconnect, connect), and the bridges support this.

Type Parameters

Type Parameter
TRouter

Parameters

ParameterTypeDescription
BridgeCtorPlayRouterBridgeConstructor<TRouter>The bridge class. The provider builds it as new BridgeCtor(router, actor, routeMap).

Returns

A PlayRouterProvider component. It is generic over the actor type. Therefore the renderer callback receives the same concrete actor type as the prop.

<TActor>(__namedParameters) => Element

Example

export const PlayRouterProvider = createPlayRouterProvider(ReactRouterBridge);