React Components and Hooks¶
Slot and page contributions can be React components (ComponentType<P> from React). The host mounts them inside a scoped bridge context and an error boundary.
Slot component example¶
import { memo } from "react";
import type { BranchRowSlotProps } from "@lore-vcs/desktop-plugins-sdk";
export const Badge = memo(function Badge({ branchName }: BranchRowSlotProps) {
return <span title={branchName}>{branchName}</span>;
});
Page component example¶
Page components receive EmptySlotProps (no props). Use hooks to access data:
import { createPluginDataHook } from "@lore-vcs/desktop-plugins-sdk/react";
import type { MyContract } from "./contract";
const usePluginData = createPluginDataHook<MyContract>();
export default function ProblemsPage() {
const [problems] = usePluginData("problems");
return <div>{JSON.stringify(problems)}</div>;
}
Hooks from @lore-vcs/desktop-plugins-sdk/react¶
The SDK exports these hooks:
import {
useBridge,
useEvents,
useCurrentRepository,
createPluginDataHook,
} from "@lore-vcs/desktop-plugins-sdk/react";
useBridge()¶
Returns your per-plugin PluginBridge. It is cheap and safe to call from any component inside a plugin surface subtree. It throws if called outside one.
When the owning plugin is dormant, useBridge() throws synchronously. The host's error boundary catches it and retries when the bridge appears. See the dormant-state behaviour table for the full breakdown across both component types. Prefer usePluginData over useBridge().data, because it handles dormancy gracefully (it returns undefined rather than throwing).
useEvents(type, handler)¶
Subscribes to a host event for the lifetime of the mount and disposes automatically on unmount. The handler receives an array of payloads (same-type events within a 16 ms window are coalesced).
Returns a stable Disposable you can call early if needed.
import { useEvents } from "@lore-vcs/desktop-plugins-sdk/react";
useEvents("repository.opened", (payloads) => {
for (const repo of payloads) {
console.log("opened:", repo);
}
});
The handler identity does not matter. The hook stores it in a ref and subscribes only when bridge or type changes, so inline arrow functions are safe.
Subscribing to an event your manifest does not declare rejects at subscribe time, and the hook re-throws. Declare the event, or catch the error if you want to degrade gracefully.
useCurrentRepository()¶
Returns the active { path, name } | null.
import { useCurrentRepository } from "@lore-vcs/desktop-plugins-sdk/react";
function MyComponent() {
const repo = useCurrentRepository();
if (!repo) return <span>No repository</span>;
return <span>{repo.name}</span>;
}
This is a convenience wrapper over bridge.data.on("repository.current", ...). Its real value is degrading to null when the subscription fails (for example on a missing grant) instead of throwing. A plugin without the data:repository.current grant therefore does not crash the component tree. The equivalent raw-bridge code:
const bridge = useBridge();
const [repo, setRepo] = useState<{ path: string; name: string } | null>(null);
useEffect(() => {
const sub = bridge.data.on("repository.current", (value) => {
setRepo(value);
});
return () => sub.dispose();
}, [bridge]);
createPluginDataHook<C>()¶
Creates a typed usePluginData hook bound to your plugin's contract. Call it once at module level:
import { createPluginDataHook } from "@lore-vcs/desktop-plugins-sdk/react";
import type { MyContract } from "./contract";
const usePluginData = createPluginDataHook<MyContract>();
The returned value is typed as T | undefined, because the hook can be read before the owning plugin has activated or exposed the key.
The hook enforces an ownership rule: whichever side (main or renderer) exposed a key is the only side that may write it:
interface MyContract extends PluginContract {
main: {
data: {
counter: number; // main-owned
};
};
renderer: {
data: {
theme: string; // renderer-owned
};
};
}
const usePluginData = createPluginDataHook<MyContract>();
// Renderer-owned key -> [value, setter]
const [theme, setTheme] = usePluginData("theme");
setTheme("dark");
// Main-owned key -> [value] only
const [counter] = usePluginData("counter");
// Destructuring a setter from a main-owned key is a compile error:
// const [, setCounter] = usePluginData("counter");
// ^^^^^^^^^^ TS error: tuple has no element at index 1
// Foreign key -> [value] only
const [status] = usePluginData("plugin:other-plugin/status");
At runtime, a non-owner write is a silent no-op.
EDS primitives¶
Import @epicgames/eds-react directly. The SDK does not re-export EDS.
import { Button, Tooltip } from "@epicgames/eds-react";
function MyToolbarAction() {
return (
<Tooltip content="Run analysis">
<Button size="small" variant="ghost" onPress={() => runAnalysis()}>
Analyze
</Button>
</Tooltip>
);
}
Declare it as a peer dependency, paired with a devDependency at the same range:
"peerDependencies": { "@epicgames/eds-react": "^3.12.0" },
"devDependencies": { "@epicgames/eds-react": "^3.12.0" }
The peer dependency records that the host supplies EDS. The build pipeline externalizes @epicgames/eds-react, so your import resolves to the host's single instance at runtime and your bundle must not ship its own. The devDependency is what lets your package typecheck and test on its own.
Why EDS comes from the host¶
Bundling your own copy fails in two ways that are easy to miss:
- Version skew. EDS bakes its version into every generated identifier:
highDensityThemeClassis the literaleds_350_jje3030, andthemeVars.*arevar(--eds_350_...)strings. Two copies of the same version are identical and harmless, but once the host upgrades, your copy references custom properties the host's theme class no longer defines, and colour and spacing silently resolve to nothing. - Duplicated react-aria state. EDS depends on react-aria, which tracks focus scopes,
aria-hiddenrefcounts, body scroll-lock and focus-visible modality in module-level state over a singledocument. Two copies each believe they own the innermost overlay, so your overlays stop cooperating with the host's: nodes are leftaria-hidden, scroll-lock is released early, and focus rings desync.
Portalled components need their own EDSProvider¶
Modal, Tooltip, ComboBox and anything built on EDS's internal popover read themeClass from EDSContext so they can re-apply the theme to portalled content. The host does not wrap plugin surfaces in an EDSProvider, so if you render any of them, supply your own or the portalled subtree renders unthemed:
import { EDSProvider, highDensityThemeClass, Modal } from "@epicgames/eds-react";
export function MyDialog() {
return (
<EDSProvider themeClass={highDensityThemeClass}>
<Modal aria-label="my-dialog">...</Modal>
</EDSProvider>
);
}
EDS icons¶
Import icons as @epicgames/eds-react/icons/<Name>. The plugin build (lore-plugin build) rewrites each such import to a named import off the externalized @epicgames/eds-react barrel, so your bundle never carries its own copy and needs no import-map entry. Any icon that exists in the host's EDS version works, in development and in a packaged build alike.
Note
Inside the Lore Desktop repository, the equivalent build step is pnpm build:plugins.
What happens with a wrong icon name depends on whether @epicgames/eds-react is installed in your plugin's dependency tree:
- Installed: the build checks the name against the barrel and fails on a name that is not an icon.
- Not installed: the build emits the import on trust and prints
warning: could not verify N EDS icon import(s) (@epicgames/eds-react not found): .... A wrong name then fails when the host imports the renderer bundle, and the plugin's row in the Plugins screen shows the load error.
A plugin with a renderer that you scaffold outside the repository already lists @epicgames/eds-react as a peer and devDependency, so its icons are checked. If your plugin doesn't, add both, as the peer/dev pairing above shows.
Next¶
The hooks above cover React components. If your plugin also uses defineJsComponent for framework-agnostic components, the next page covers the imperative equivalent of everything here.