i don't have the service worker file in react code example

Example 1: service worker.js

if ('serviceWorker' in navigator) {  window.addEventListener('load', function() {    navigator.serviceWorker.register('/sw.js').then(function(registration) {      // Registration was successful      console.log('ServiceWorker registration successful with scope: ', registration.scope);    }, function(err) {      // registration failed :(      console.log('ServiceWorker registration failed: ', err);    });  });}

Example 2: react web worker

import {    IonContent,    IonPage,    IonLabel,    IonButton} from '@ionic/react';import React, {useState} from 'react';import {RouteComponentProps} from 'react-router';import './Page.css';const Page: React.FC> = ({match}) => {    const [countTomato, setCountTomato] = useState(0);    const [countApple, setCountApple] = useState(0);    function incApple() {        const start = Date.now();        while (Date.now() < start + 5000) {        }        setCountApple(countApple + 1);    }    return (                                    Tomato: {countTomato} | Apple: {countApple}                
setCountTomato(countTomato + 1)} color="primary">Tomato incApple()} color="secondary">Apple
);};export default Page;

Tags:

Misc Example