Martin Dimitrov 25438f7901
Some checks failed
Build and push image for doorman-homeassistant / docker (push) Successful in 28s
Build and push Doorman UI / API / docker (push) Failing after 17s
Build and push image for doorman-homeassistant / deploy-gitainer (push) Successful in 22s
launch edit api
2024-11-12 21:46:45 -08:00

25 lines
539 B
TypeScript

import React from "react";
import { ReactNode } from "react";
import { useLocation, useSearchParams } from "react-router-dom";
export interface IQueryRouterProps {
mapping: Record<string, ReactNode>;
};
export const QueryRouter = ({ mapping }: IQueryRouterProps) => {
const [params] = useSearchParams();
let element = null;
for (const key of params.keys()) {
if (mapping[key]) {
element = mapping[key];
break;
}
}
if (element === null) {
throw new Error("missing mapping");
}
return element;
};