-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
33 lines (30 loc) · 1.01 KB
/
Copy pathindex.tsx
File metadata and controls
33 lines (30 loc) · 1.01 KB
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
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import "./index.css";
import * as serviceWorkerRegistration from "./serviceWorkerRegistration";
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
serviceWorkerRegistration.register({
// Force updates to service worker to be installed immediately
// (The page will reload.)
// via https://github.com/facebook/create-react-app/issues/5316#issuecomment-496292914 and https://stackoverflow.com/q/52904430
onUpdate: (registration) => {
const waitingServiceWorker = registration.waiting;
if (waitingServiceWorker) {
waitingServiceWorker.addEventListener("statechange", (event) => {
const target = event.target as ServiceWorker;
if (target.state === "activated") {
window.location.reload();
}
});
waitingServiceWorker.postMessage({ type: "SKIP_WAITING" });
}
},
});