Skip to content

Instantly share code, notes, and snippets.

@Leejjon
Created July 2, 2020 20:52
Show Gist options
  • Save Leejjon/9fa95e5c474331c64324ed07d6ec8cf3 to your computer and use it in GitHub Desktop.
Save Leejjon/9fa95e5c474331c64324ed07d6ec8cf3 to your computer and use it in GitHub Desktop.
index.tsx file with update mechanism for the service worker
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import {Config} from "./serviceWorker";
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
const config: Config = {
onUpdate: (registration) => {
if (registration && registration.waiting) {
registration.waiting.postMessage({ type: 'SKIP_WAITING' });
window.location.reload();
}
},
};
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.register(config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment