useTray
A system tray icon + context menu. Electron only meaningfully supports one tray icon per app, so the hook is a singleton — the first component that mounts it creates the tray; unmounting destroys it.
const { setToolTip, setMenu, onClick } = useTray({ tooltip: 'My App', menu: [...] })
| Param/Member | Type | Notes |
|---|---|---|
options.tooltip | string | Initial tooltip. |
options.menu | NextopAppMenuItem[] | Initial context menu (same shape as useMenu). |
options.icon | string | Overrides the default assets/favicon.ico. |
setToolTip | (tooltip: string) => void | Update the tooltip after creation. |
setMenu | (menu: NextopAppMenuItem[]) => void | Replace the context menu after creation. |
onClick | (callback: () => void) => () => void | Subscribes to tray icon clicks; returns an unsubscribe function. |
'use client'import { useTray } from 'nextop-app'export default function TrayIcon() {useTray({ tooltip: 'My App', menu: [{ role: 'quit' }] })return null}
Call
useTrayfrom exactly one component. The "singleton" is enforced on the main-process side (a secondtray:createis a no-op), buttray:destroyfires unconditionally on unmount — if a second component also mounts/unmountsuseTray, it will tear down the tray the first component is still relying on.