UNPKG

@koordinates/xstate-tree

Version:

Build UIs with Actors using xstate and React

24 lines (23 loc) 967 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useOnRoute = void 0; const providers_1 = require("./providers"); /** * @public * Accepts a single Route and returns true if the route is currently active and marked as an index route. * False if not. * * If used outside of a RoutingContext, an error will be thrown. * @param route - the route to check * @returns true if the route is active and an index route, false if not * @throws if used outside of an xstate-tree root */ function useOnRoute(route) { const activeRouteEvents = (0, providers_1.useActiveRouteEvents)(); if (!activeRouteEvents) { throw new Error("useOnRoute must be used within a RoutingContext. Are you using it outside of an xstate-tree Root?"); } return activeRouteEvents.some((activeRouteEvent) => activeRouteEvent.type === route.event && activeRouteEvent.meta?.indexEvent === true); } exports.useOnRoute = useOnRoute;