Service Worker

Update pop-up

Easily prompt the user to instantly update their app when a new version is available, and already ready to use.

const [shouldUpdate, update] = useServiceWorkerUpdate()

if (shouldUpdate) {
	return (
		<div>
			<p>A new version is available</p>
			<button onClick={update}>Update</button>
		</div>
	)
}

Service Worker communication

Easily communicate with the Service Worker for advanced offline capabilities. Of course, postMessage is type-safe.

const { data: sw } = useServiceWorker()
useEffect(() => {
	if (!sw) return
	sw.postMessage({
		type: "TASK",
		payload: {
			foo: "Do this thing",
		},
	})
}, [sw])