Skip to main content
Version: 1.0.4

useCustomNotificationCenter

@spartanfx/react v1.0.4


@spartanfx/react / useCustomNotificationCenter

Function: useCustomNotificationCenter()

useCustomNotificationCenter(store?): INotificationCenterHook

Hook for managing notifications with a custom store implementation

Can be used in two ways:

  1. With store: Creates a new custom notification center instance
  2. Without store: Accesses the notification center from context

Parameters

store?

INotificationCenterStore

Returns

INotificationCenterHook

Example

// Create a custom store
const customStore: INotificationCenterStore = {
load: async () => {
const response = await fetch('/api/notifications');
return response.json();
},
add: async (item) => {
const response = await fetch('/api/notifications', {
method: 'POST',
body: JSON.stringify(item),
});
return response.json();
},
update: async (id, patch) => {
await fetch(`/api/notifications/${id}`, {
method: 'PATCH',
body: JSON.stringify(patch),
});
},
remove: async (id) => {
await fetch(`/api/notifications/${id}`, { method: 'DELETE' });
},
clear: async () => {
await fetch('/api/notifications', { method: 'DELETE' });
},
};

// Create instance (at app root)
const config = useCustomNotificationCenter(customStore);
<NotificationCenterProvider config={config}>...</NotificationCenterProvider>

// Access from context (in child components)
const { addNotification, items } = useCustomNotificationCenter();