All skills

Practical playbook for React teams to choose and apply reactuse hooks across state, async flows, browser APIs, and UI interactions. Use it when replacing custom hook logic with production-ready patterns that stay compatible with SSR and Next.js.

Use this Skill: https://skilld.dev/gh/siberiacancode/agent-skills/reactuse

This session only. Nothing lands on disk.

rulesuseWebWorker.md

≈489 tokens on demand. Your agent reads this file only when SKILL.md points to it.

useWebWorker

Keeps a Web Worker connected to React state so components can post messages, restart work, terminate it, and render the latest result or error.

Usage

import { useWebWorker } from "@siberiacancode/reactuse";

const worker = useWebWorker<number>("/worker.js");

Example

import { useWebWorker } from "@siberiacancode/reactuse";

export const WorkerCounter = () => {
  const worker = useWebWorker<number>("/counter-worker.js");

  return (
    <div>
      <button onClick={() => worker.post("next")}>Next</button>
      <span>{worker.data ?? 0}</span>
      <button onClick={worker.terminate}>Stop</button>
    </div>
  );
};

source as URL:

const worker = useWebWorker(new URL("./worker.ts", import.meta.url));

source as Worker:

const worker = useWebWorker(new Worker("/worker.js"));

WorkerOptions:

const worker = useWebWorker("/worker.js", { type: "module" });

onError:

const worker = useWebWorker("/worker.js", {
  onError: (event) => console.error(event),
});

onMessage:

const worker = useWebWorker<number>("/worker.js", {
  onMessage: (data) => console.log(data),
});

Notes

Type Declarations

export type UseWebWorkerSource = string | URL | Worker;
export interface UseWebWorkerOptions<Data = unknown> extends WorkerOptions {
  onError?: (event: Event) => void;
  onMessage?: (data: Data, event: MessageEvent<Data>) => void;
}
export interface UseWebWorkerReturn<Data = unknown> {
  data?: Data;
  error?: Event;
  post: Worker["postMessage"];
  terminated: boolean;
  restart: () => void;
  terminate: () => void;
}
export declare const useWebWorker: <Data = unknown>(
  source: UseWebWorkerSource,
  options?: UseWebWorkerOptions<Data>
) => UseWebWorkerReturn<Data>;

Source: SKILL.md on GitHub

No alerts16d4 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill is a comprehensive documentation and implementation guide for the Reactuse hook library, designed for React and Next.js projects. It provides clear rules, usage examples, and type declarations for a wide range of hooks, including those interacting with browser APIs. No malicious patterns, obfuscation, or security risks were detected.

  • Socket5mo

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    1/166 files flagged

Signed by skilld at a090849. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated last month
metadata
{
  "author": "siberiacancode",
  "version": "1.0.16"
}

README badge

README badge for siberiacancode/agent-skills/reactuse