useCustomNotificationCenter
@spartanfx/react / useCustomNotificationCenter
Function: useCustomNotificationCenter()
useCustomNotificationCenter(
store?):INotificationCenterHook
Hook for managing notifications with a custom store implementation
Can be used in two ways:
- With store: Creates a new custom notification center instance
- Without store: Accesses the notification center from context
Parameters
store?
Returns
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();