openpanel/packages/devtools-ui/src/components/monitor-highlight-handler.tsx
Stefan Pejcic 8595a9f4e5 back
2024-05-08 19:58:53 +02:00

33 lines
757 B
TypeScript

import React, { useContext } from "react";
import { useNavigate } from "react-router-dom";
import {
DevToolsContext,
DevtoolsEvent,
receive,
} from "@refinedev/devtools-shared";
export const MonitorHighlightHandler = () => {
const navigate = useNavigate();
const { ws } = useContext(DevToolsContext);
React.useEffect(() => {
if (!ws) return () => 0;
const unsub = receive(
ws,
DevtoolsEvent.DEVTOOLS_HIGHLIGHT_IN_MONITOR_ACTION,
({ name }) => {
if (name) {
navigate(`/monitor?highlight=${name}`);
}
},
);
return () => {
unsub();
};
}, [ws, navigate]);
return null;
};