How to use react-hooks-worker - 8 common examples

To help you get started, we’ve selected a few react-hooks-worker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dai-shi / react-hooks-worker / examples / 05_generator / src / slow_fib.worker.js View on Github external
async function* fib(x) {
  let x1 = 0;
  let x2 = 1;
  let i = 0;
  while (i < x) {
    yield `(calculating...) ${x1}`;
    // eslint-disable-next-line no-await-in-loop
    await new Promise((r) => setTimeout(r, 100));
    [x1, x2] = [x2, x1 + x2];
    i += 1;
  }
  yield x1;
}

exposeWorker(fib);
github dai-shi / react-hooks-worker / examples / 01_minimal / src / slow_fib.worker.js View on Github external
import { exposeWorker } from 'react-hooks-worker';

const fib = (i) => (i <= 1 ? i : fib(i - 1) + fib(i - 2));

exposeWorker(fib);
github dai-shi / react-hooks-worker / examples / 03_comparison / src / slow_fib.worker.js View on Github external
import { exposeWorker } from 'react-hooks-worker';

const fib = (i) => (i <= 1 ? i : fib(i - 1) + fib(i - 2));

exposeWorker(fib);
github dai-shi / react-hooks-worker / examples / 02_typescript / src / slow_fib.worker.js View on Github external
import { exposeWorker } from 'react-hooks-worker';

const fib = (i) => (i <= 1 ? i : fib(i - 1) + fib(i - 2));

exposeWorker(fib);
github dai-shi / react-hooks-worker / examples / 04_inline / src / CalcFib.tsx View on Github external
const CalcFib: React.FC<{ count: number }> = ({ count }) => {
  const { result, error } = useWorker(createWorker, count);
  if (error) return <div>Error: {error}</div>;
  return <div>Result: {result}</div>;
};
github dai-shi / react-hooks-worker / examples / 03_comparison / src / CalcFib.tsx View on Github external
const CalcFib: React.FC&lt;{ count: number }&gt; = ({ count }) =&gt; {
  const { result, error } = useWorker('./slow_fib.js', count);
  if (error) return <div>Error: {error}</div>;
  return <div>Result: {result}</div>;
};
github dai-shi / react-hooks-worker / examples / 05_generator / src / CalcFib.tsx View on Github external
const CalcFib: React.FC&lt;{ count: number }&gt; = ({ count }) =&gt; {
  const { result, error } = useWorker(createWorker, count);
  if (error) return <div>Error: {error}</div>;
  return <div>Result: {result}</div>;
};
github dai-shi / react-hooks-worker / examples / 01_minimal / src / index.js View on Github external
const CalcFib = ({ count }) =&gt; {
  const { result, error } = useWorker(createWorker, count);
  if (error) return <div>Error: {error}</div>;
  return <div>Result: {result}</div>;
};

react-hooks-worker

React custom hooks for web workers

MIT
Latest version published 1 year ago

Package Health Score

51 / 100
Full package analysis

Popular JavaScript code snippets

Find secure code to use in your application or website