Repository navigation
hook notificationevents
useNotificationEvents is a shared, generic React hook for publishing and subscribing to application notification events. It wraps the Notification context and exposes helpers for sending toast or inline events, subscribing to event types, and clearing scoped notifications. It is not waste-specific.
import useNotificationEvents from '@/hooks/useNotificationEvents';
const Component = () => {
const { sendToastEvent, subscribe } = useNotificationEvents();
useEffect(() => {
const off = subscribe('info', (event) => {
console.log(event.title, event.description);
});
return () => off();
}, [subscribe]);
const handleClick = () => {
sendToastEvent({
eventType: 'info',
title: 'Saved',
description: 'Changes were saved.',
eventTarget: 'my-page',
});
};
return <button onClick={handleClick}>Save</button>;
};- Wraps
useNotificationfromNotificationProvider. -
sendToastEventforcesdisplayMode: 'toast'. -
sendInlineEventforcesdisplayMode: 'inline'. -
sendEventpasses through without forcing display mode. -
subscribeandunsubscribeoperate byEventType. -
clearEventsdispatches aclear-eventsinfo event for scoped clearing.
function useNotificationEvents(): {
clearEvents: (eventTarget?: string) => void;
sendEvent: (event: GlobalEvent) => void;
sendInlineEvent: (event: Omit<GlobalEvent, 'displayMode'>) => void;
sendToastEvent: (event: Omit<GlobalEvent, 'displayMode'>) => void;
subscribe: (eventType: EventType, listener: EventListener) => () => void;
unsubscribe: (eventType: EventType, listener: EventListener) => void;
}Key types
-
EventType:'error' | 'info' | 'success' | 'warning' -
NotificationDisplayMode:'inline' | 'toast' -
GlobalEvent:title,description,eventType, optionaltimeout,eventTarget,displayMode,meta
Decouples event producers from consumers and supports scoped page clears without tying components to waste domain logic.
For more hooks, see Contexts & Hooks.
This wiki documents NR Waste Plus for users and developers. Verify security and deployment guidance against the current application configuration before applying it elsewhere.
- Report an issue or ask a question in the GitHub repository.
- Follow the Contributing Guidelines to propose an update.
- Read the Code of Conduct.
Collection indexes support human browsing and machine retrieval. Keep both current when adding or moving wiki pages.
NR Waste Plus Wiki | GitHub Repository