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.

rulesuseMediaStream.md

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

useMediaStream

Connects camera or microphone capture to a media element while exposing stream lifecycle state and constraint updates.

Usage

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

const media = useMediaStream<HTMLVideoElement>();
// or
const media = useMediaStream(videoRef, { constraints: { video: true } });

Example

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

export const CameraPreview = () => {
  const media = useMediaStream<HTMLVideoElement>({
    constraints: { video: true, audio: false },
  });

  return (
    <div>
      <video ref={media.ref} autoPlay muted playsInline />
      <button onClick={() => media.start()}>Start</button>
      <button onClick={media.stop}>Stop</button>
    </div>
  );
};

constraints:

const media = useMediaStream<HTMLVideoElement>({
  constraints: { video: true, audio: false },
});

immediately:

const media = useMediaStream(videoRef, { immediately: true });

onError:

const media = useMediaStream({ onError: (error) => console.error(error) });

onStart:

const media = useMediaStream({
  onStart: (stream) => console.log(stream.id),
});

onStop:

const media = useMediaStream({ onStop: () => console.log("stopped") });

apply(constraints):

await media.apply({ video: { width: 1280 } });

Notes

Type Declarations

import type { HookTarget, StateRef } from "@siberiacancode/reactuse";

export interface UseMediaStreamOptions {
  constraints?: MediaStreamConstraints;
  immediately?: boolean;
  onError?: (error: Error) => void;
  onStart?: (stream: MediaStream) => void;
  onStop?: (stream?: MediaStream) => void;
}
export interface UseMediaStreamReturn {
  active: boolean;
  loading: boolean;
  stream?: MediaStream;
  supported: boolean;
  apply: (constraints: MediaStreamConstraints) => Promise<boolean>;
  restart: () => Promise<MediaStream | undefined>;
  start: (constraints?: MediaStreamConstraints) => Promise<MediaStream | undefined>;
  stop: () => void;
}
export interface UseMediaStream {
  (target: HookTarget, options?: UseMediaStreamOptions): UseMediaStreamReturn;
  (options?: UseMediaStreamOptions): UseMediaStreamReturn & {
    ref: StateRef<HTMLVideoElement>;
  };
}
export declare const useMediaStream: UseMediaStream;

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