@magicbell/react-headless
Version:
Hooks to build a notification inbox
30 lines • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = useBell;
const tslib_1 = require("tslib");
const useNotifications_js_1 = tslib_1.__importDefault(require("./useNotifications.js"));
/**
* Hook to get a notification store to be used in a bell.
*
* The `markAllAsSeen` function exposed by this hook does not update the fetched
* notifications.
*
* @param props
* @param props.storeId Optional ID of the notifications store
* @returns A store of notifications (if the store exists)
*
* @example
* const { unreadCount, markAllAsSeen } = useBell();
*/
function useBell({ storeId } = {}) {
const store = (0, useNotifications_js_1.default)(storeId);
const markAllAsSeen = () => {
if (store && store.unseenCount > 0)
return store?.markAllAsSeen({ updateModels: false });
return Promise.resolve(true);
};
if (store)
return { ...store, markAllAsSeen };
return null;
}
//# sourceMappingURL=useBell.js.map