Nnextop / app

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/MemberTypeNotes
options.tooltipstringInitial tooltip.
options.menuNextopAppMenuItem[]Initial context menu (same shape as useMenu).
options.iconstringOverrides the default assets/favicon.ico.
setToolTip(tooltip: string) => voidUpdate the tooltip after creation.
setMenu(menu: NextopAppMenuItem[]) => voidReplace the context menu after creation.
onClick(callback: () => void) => () => voidSubscribes 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 useTray from exactly one component. The "singleton" is enforced on the main-process side (a second tray:create is a no-op), but tray:destroy fires unconditionally on unmount — if a second component also mounts/unmounts useTray, it will tear down the tray the first component is still relying on.