@magicbell/react-headless
Version:
Hooks to build a notification inbox
25 lines • 821 B
JavaScript
import { useEffect } from 'react';
/**
* Hook that is ran when the component is unmounted. By default marks a
* notification as seen.
*
* @param notification The notification
* @param fn Callback function to execute when the component is unmounted
*
* @example
* useNotificationUnmount(notification);
*/
export default function useNotificationUnmount(notification, fn) {
useEffect(() => {
return () => {
if (fn)
fn(notification);
else
notification.markAsSeen();
};
// TODO: Update code to follow lint suggestions of add missing dependencies,
// remove [] or wrap parent component in callback
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}
//# sourceMappingURL=useNotificationUnmount.js.map