In-App Notifications for Next.js Apps
Add a notification bell to your Next.js app using the Notilayer script tag and next/script. No npm package to install. Works with App Router and Pages Router. Real-time delivery via SSE.
App Router
Add to layout.tsx in 30 seconds
Import next/script and add the Notilayer widget script to your root layout. Set strategy="afterInteractive" so it loads after hydration. That is it. The bell icon and inbox render automatically.
Import next/script
Built into Next.js. No additional package needed.
Add the Script tag
Pass your App ID via the data-app-id attribute. Get it from the Notilayer dashboard.
Bell appears automatically
The widget renders a bell icon with an inbox. Real-time updates via SSE.
app/layout.tsx
// app/layout.tsx
import Script from 'next/script';
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{children}
<Script
src="https://api.notilayer.com/widget/widget.js"
data-app-id="YOUR_APP_ID"
strategy="afterInteractive"
/>
</body>
</html>
);
} components/NotilayerInit.tsx
'use client';
import { useEffect } from 'react';
export function NotilayerInit() {
useEffect(() => {
// Widget auto-initializes after script loads
// Use this hook to set the user ID
if (window.Notilayer) {
window.Notilayer.identify('user_123');
}
}, []);
return null;
} User Identification
Identify users with useEffect
The widget loads and initializes automatically. To show user-specific notifications, call window.Notilayer.identify() with the user's ID after authentication. Wrap this in a 'use client' component since it accesses the window object.
- Works with Server Components — widget loads via script tag, not React
- Call identify() after your auth check resolves
- SSE connection opens automatically after identification
Pages Router
Works with _app.tsx too
If your Next.js project uses the Pages Router, add the Notilayer script in pages/_app.tsx. Same component, same strategy. The widget behavior is identical regardless of which router you use.
Same next/script API
The Script component works the same way in both routers. No differences in configuration.
Persists across navigations
Since _app.tsx wraps all pages, the widget stays mounted during client-side route transitions.
No hydration mismatch
The script loads after hydration completes. No SSR/client mismatch warnings.
pages/_app.tsx
// pages/_app.tsx (Pages Router)
import Script from 'next/script';
import type { AppProps } from 'next/app';
export default function App({
Component, pageProps
}: AppProps) {
return (
<>
<Component {...pageProps} />
<Script
src="https://api.notilayer.com/widget/widget.js"
data-app-id="YOUR_APP_ID"
strategy="afterInteractive"
/>
</>
);
} Compatibility
Built for the Next.js ecosystem
The widget is framework-agnostic by design. Here is why it works seamlessly with Next.js projects of any complexity.
Shadow DOM
Widget styles are fully isolated. Your Tailwind, CSS Modules, or styled-components will not leak into the widget.
SSR Safe
Loads with afterInteractive strategy. No server-side rendering issues, no hydration mismatches, no window errors.
No Bundle Impact
External script loads asynchronously. Zero impact on your Next.js bundle size and build time.
Route Transitions
Widget persists during client-side navigation. Bell state and inbox position are maintained across page changes.
Why Script Tag?
Script tag vs. npm package for notifications
For a notification widget, a script tag is often the better choice. Here is why. Also see our React bell guide.
| Aspect | Script Tag | npm Package |
|---|---|---|
| Setup steps | 1 line | Install, import, configure |
| Bundle size impact | 0 KB | Added to bundle |
| Version updates | Automatic | Manual npm update |
| Framework coupling | None | React-specific |
| SSR compatibility | Built-in | Needs dynamic import |
FAQ
Next.js integration questions
How do I add in-app notifications to a Next.js app without an npm package?
Does the Notilayer widget work with Next.js Server Components?
Will the Notilayer widget styles conflict with my Next.js app styles?
Can I use the Notilayer script tag with both the App Router and Pages Router?
Explore more: Home · React Bell Guide · React Notifications Tutorial
Add Notifications to Your Next.js App
One script tag. No npm package. Real-time delivery. Free plan included.