Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
react-hooks-worker
Advanced tools
React custom hooks for web workers.
React Hooks API is promising. Web Workers API is promising.
This is an experimental library to provide an easy way to call web workers. It's more or less for fun, but feedbacks are welcome to make this for production.
npm install react-hooks-worker
import React from 'react';
import { useWorker } from 'react-hooks-worker';
const calcFib = (x) => {
const fib = i => (i <= 1 ? i : fib(i - 1) + fib(i - 2));
return fib(x);
};
const CalcFib: React.FC<{ count: number }> = ({ count }) => {
const { result, error } = useWorker(calcFib, count);
if (error) return <div>Error:{error}</div>;
return <div>Result:{result}</div>;
};
const App = () => (
<div>
<CalcFib count={5} />
</div>
);
Parcel allow your Web Worker script to be automatically bundled. To do this, just pass an instance of the Web Worker instead of the url:
const myWorker = new Worker("./slow_fib.js")
const { result, error } = useWorker(myWorker, count);
The examples folder contains working examples. You can run one of them with
PORT=8080 npm run examples:minimal
and open http://localhost:8080 in your web browser.
You can also try them in codesandbox.io: 01 02 03 04 05
FAQs
React custom hooks for web workers
The npm package react-hooks-worker receives a total of 768 weekly downloads. As such, react-hooks-worker popularity was classified as not popular.
We found that react-hooks-worker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.