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.

rulesuseMutationObserver.md

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

useMutationObserver

Observes DOM mutations on an element.

Usage

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

const observer = useMutationObserver<HTMLDivElement>({ childList: true });
// or
const observer = useMutationObserver(ref, { childList: true });

Example

import { useMutationObserver } from "@siberiacancode/reactuse";
import { useState } from "react";

export const AttributeWatch = () => {
  const [count, setCount] = useState(0);
  const observer = useMutationObserver<HTMLDivElement>({
    attributes: true,
    onChange: () => setCount((value) => value + 1),
  });

  return (
    <div disabled={count % 2 === 0} ref={observer.ref}>
      Changes: {count}
    </div>
  );
};

enabled:

Toggle observer.

const observer = useMutationObserver<HTMLDivElement>({ enabled: false });

onChange:

Mutation callback.

const observer = useMutationObserver<HTMLDivElement>({
  onChange: (mutations) => console.log(mutations),
});

attributes:

Watch attributes.

const observer = useMutationObserver<HTMLDivElement>({ attributes: true });

characterData:

Watch text.

const observer = useMutationObserver<HTMLDivElement>({ characterData: true });

childList:

Watch children.

const observer = useMutationObserver<HTMLDivElement>({ childList: true });

subtree:

Watch descendants.

const observer = useMutationObserver<HTMLDivElement>({ subtree: true });

Notes

Type Declarations

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

export type UseMutationObserverCallback = (
  mutations: MutationRecord[],
  observer: MutationObserver
) => void;
export interface UseMutationObserverOptions extends MutationObserverInit {
  enabled?: boolean;
  onChange?: UseMutationObserverCallback;
}
export interface UseMutationObserverReturn {
  observer?: MutationObserver;
}
export interface UseMutationObserver {
  <Target extends Element>(
    options?: UseMutationObserverOptions,
    target?: never
  ): UseMutationObserverReturn & { ref: StateRef<Target> };
  (
    target: HookTarget,
    options?: UseMutationObserverOptions
  ): UseMutationObserverReturn;
  <Target extends Element>(
    callback: UseMutationObserverCallback,
    target?: never
  ): UseMutationObserverReturn & { ref: StateRef<Target> };
  (
    target: HookTarget,
    callback: UseMutationObserverCallback
  ): UseMutationObserverReturn;
}
export declare const useMutationObserver: UseMutationObserver;

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