UNPKG

@koordinates/xstate-tree

Version:

Build UIs with Actors using xstate and React

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