rozenite-custom-commands
Version:
Add and execute custom commands in React Native via React Native DevTools powered by Rozenite
30 lines (29 loc) • 809 B
JavaScript
import { useRozeniteDevToolsClient as u } from "@rozenite/plugin-bridge";
import { useEffect as d } from "react";
const f = (m) => {
const n = u({
pluginId: "rozenite-custom-commands"
});
return d(() => {
if (!n) return;
const e = new Map(m.map((o) => [o.id, o.command])), t = () => {
n.send("custom-commands", {
commands: m.map(({ id: o, title: s, description: r, category: i }) => ({
id: o,
title: s,
description: r,
category: i
}))
});
}, a = n.onMessage("request-initial", t), c = n.onMessage("command-callback", (o) => {
const s = e.get(o.id);
s && s(o == null ? void 0 : o.args);
});
return () => {
a.remove(), c.remove();
};
}, [n, m]), n;
};
export {
f as useCustomCommands
};