worker js in react code example
Example: 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<RouteComponentProps<{ name: string; }>> = ({match}) => { const [countTomato, setCountTomato] = useState<number>(0); const [countApple, setCountApple] = useState<number>(0); function incApple() { const start = Date.now(); while (Date.now() < start + 5000) { } setCountApple(countApple + 1); } return ( <IonPage> <IonContent className="ion-padding"> <IonLabel>Tomato: {countTomato} | Apple: {countApple}</IonLabel> <div className="ion-padding-top"> <IonButton onClick={() => setCountTomato(countTomato + 1)} color="primary">Tomato</IonButton> <IonButton onClick={() => incApple()} color="secondary">Apple</IonButton> </div> </IonContent> </IonPage> );};export default Page;