custom-notification-bell
Version:
A customizable notification bell component
61 lines (47 loc) • 1.96 kB
Markdown
[](https://www.npmjs.com/package/custom-notification-bell)
[](https://www.npmjs.com/package/custom-notification-bell)
[](LICENSE)
A reusable React notification bell component for **real-time notifications** via WebSocket and REST API.
Designed to be framework-agnostic: no hardcoded navigation — you decide what happens when users click notifications.
---
- 📡 **Real-time updates** via WebSocket
- 📥 **Fetch past notifications** via REST API
- 🎨 **Customizable icon & theme**
- ⚡ **Lightweight, no extra dependencies**
- 🛠️ **Pluggable navigation** (`onNotificationClick`, `onSeeAllClick`)
---
```bash
npm install custom-notification-bell
yarn add custom-notification-bell
import { NotificationBell } from "custom-notification-bell";
import { BiBell } from "react-icons/bi";
import { useNavigate } from "react-router-dom";
export default function App() {
const navigate = useNavigate();
return (
<NotificationBell
websocketUrl="https://your-websocket-endpoint"
apiUrl="https://your-api/notification"
bellIcon={<BiBell size={15} />}
userId="user-123"
theme="dark"
showConnectionStatus={true}
onNotificationClick={(notification) => {
// 🔹 Host app controls navigation
if (notification.type === "comment") {
navigate(`/reviews/${notification.relatedEntity?.id}`);
} else {
navigate("/notifications");
}
}}
onSeeAllClick={() => {
navigate("/notifications");
}}
/>
);
}