UNPKG

next-pwa-pack

Version:

PWA cache provider for Next.js/React apps (service worker, manifest, offline page, SPA cache, offline)

22 lines (21 loc) 689 B
"use client"; import { useEffect } from "react"; import { updatePageCache } from "../pwaActions"; export default function SWRevalidateListener() { useEffect(() => { const handler = (e) => { if (e.key === "swRevalidate" && e.newValue) { try { const { urls } = JSON.parse(e.newValue); if (Array.isArray(urls)) { urls.forEach(updatePageCache); } } catch { } } }; window.addEventListener("storage", handler); return () => window.removeEventListener("storage", handler); }, []); return null; }