-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathApp.tsx
39 lines (34 loc) · 1019 Bytes
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { useEffect } from "react";
function App() {
useEffect(() => {
let registration: ServiceWorkerRegistration | undefined;
async function registerServiceWorker() {
// Register service worker
navigator.serviceWorker.register("./service-worker.js");
// Get registration
registration = await navigator.serviceWorker.ready;
const worker = registration.active;
if (worker) {
worker.postMessage(
"This message will trigger the 'message' in the service worker"
);
}
}
// Clean up the service worker before register the new one
navigator.serviceWorker.getRegistrations().then(registrations => {
for (const registration of registrations) {
registration.unregister();
}
});
registerServiceWorker();
return () => {
registration?.unregister();
};
}, []);
return (
<>
<div>Please checkout the "Developer Tools" for console messages.</div>
</>
);
}
export default App;