feat(web-workers):

-  add useWorker to interact with web workers declaratively

- update next to 11.1.2 to support web-workers

- update next config to ignore eslint errors during build
This commit is contained in:
Aminejv 2021-09-24 17:37:44 +01:00
parent 24b09cf0ba
commit 2c601066a6
3 changed files with 33 additions and 1 deletions

View File

@ -424,3 +424,30 @@ export const useLockScroll = ({ lock = true } = {}) => {
return () => (document.body.style.overflow = "visible");
}, [lock]);
};
export const useWorker = ({ onStart, onMessage, onError, path } = {}, dependencies = []) => {
const workerRef = React.useRef();
const onStartRef = React.useRef();
onStartRef.current = onStart;
const onMessageRef = React.useRef();
onMessageRef.current = onMessage;
const onErrorRef = React.useRef();
onErrorRef.current = onError;
React.useEffect(() => {
const worker = new Worker(new URL(path, import.meta.url));
if (!worker) return;
workerRef.current = worker;
worker.onmessage = onMessageRef.current;
worker.onerror = onErrorRef.current;
onStartRef.current(worker);
return () => worker?.terminate();
}, dependencies);
return workerRef.current;
};

View File

@ -2,6 +2,11 @@ const withOffline = require("next-offline");
const nextConfig = {
webpack5: true,
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
};
module.exports = withOffline(nextConfig);

View File

@ -65,7 +65,7 @@
"moment": "^2.29.1",
"morgan": "^1.10.0",
"multihashing-async": "^2.1.2",
"next": "^10.0.7",
"next": "^11.1.2",
"next-offline": "^5.0.5",
"oauth": "^0.9.15",
"pg": "^8.5.1",