-
-
Notifications
You must be signed in to change notification settings - Fork 246
/
WorkerTest.tsx
executable file
Β·34 lines (31 loc) Β· 1.18 KB
/
WorkerTest.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
import { Plugins } from '@capacitor/core';
import Loading from '../components/Scene/loading';
import Layout from '../components/Layout/Layout';
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
// Hack to get around a bug in Vite/rollup: https://github.com/vitejs/vite/issues/2139
import nossr from "react-no-ssr";
const NoSSR = nossr.default ? nossr.default : nossr;
export const IndexPage = (): any => {
const { t } = useTranslation();
const [messageState, setMessageState] = useState("");
useEffect(() => {
const worker = new Worker(new URL('../components/deep-thought.js', import.meta.url));
worker.postMessage({
question:
'The Answer to the Ultimate Question of Life, The Universe, and Everything.',
});
worker.onmessage = ({ data: { answer } }) => {
console.log(answer);
setMessageState(answer);
};
}, []);
return (
<Layout pageTitle={t('workerTest.pageTitle')} login={false}>
<NoSSR onSSR={<Loading/>}>
<div>{messageState}</div>
</NoSSR>
</Layout>
);
};
export default IndexPage;