minhtranite / react-notifications

Notification component for ReactJS
https://www.npmjs.com/package/react-notifications
287 stars 64 forks source link

Clear all notifications #30

Open ShivamChaurasia opened 6 years ago

ShivamChaurasia commented 6 years ago

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

dcortes92 commented 6 years ago

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.

marouan-fr commented 5 years ago

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

i think this is a 'cleaner' workaround.