react-notifications icon indicating copy to clipboard operation
react-notifications copied to clipboard

Clear all notifications

Open ShivamChaurasia opened this issue 8 years ago • 2 comments

Would be nice to have a call that clears all notifications which had no timeOut.

ShivamChaurasia avatar Oct 05 '17 09:10 ShivamChaurasia

There is an open PR (#39) to address this that will make this easier. However, I needed to clear all the notifications too, what I did as a workaround was to trigger an event when you changed the route.

If you check the source, you can see that after clicking the notification, it will trigger the requestHide. So, in my onRouteChange I add something like this:

const notifications = [].slice.call(document.querySelectorAll('.notification'))
notifications.forEach(notification => notification.click())

This will simulate a click event for each of the notifications, and hence, closing them. I hope that helps.

dcortes92 avatar Aug 09 '18 14:08 dcortes92

NotificationManager.listNotify.forEach(n => NotificationManager.remove({ id: n.id }));

i think this is a 'cleaner' workaround.

marouan-fr avatar Nov 09 '18 14:11 marouan-fr