react-refs-dom

react-refs-dom is a cursor rule for Cursor from tonyghiani/ai-essentials. It costs 0 tokens per session (660 once invoked), scanned A, original, MIT.

A set of React rules for refs and direct browser-page manipulation. A ref is a persistent value or reference to a page element that can change without causing a re-render.

In plain words
What is it for?
Use it when working with focus, scrolling, layout measurement, timers, previous values, DOM elements, or non-React widgets.
Why use it?
It helps keep display-changing values in state and prevents unsafe access to page elements during rendering. It also clarifies when cleanup and event-time access are appropriate.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it when working with focus, scrolling, layout measurement, timers, previous values, DOM elements, or non-React widgets.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/tonyghiani/ai-essentials/react-refs-dom
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/tonyghiani/ai-essentials

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for react-refs-dom

README.md
[![agentmods](https://agentmods.dev/badge/rules/tonyghiani/ai-essentials/react-refs-dom/github.svg)](https://agentmods.dev/rules/tonyghiani/ai-essentials/react-refs-dom)
Your own site
<a href="https://agentmods.dev/rules/tonyghiani/ai-essentials/react-refs-dom"><img src="https://agentmods.dev/badge/rules/tonyghiani/ai-essentials/react-refs-dom/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for react-refs-dom

Your own site · 80×15
<a href="https://agentmods.dev/rules/tonyghiani/ai-essentials/react-refs-dom"><img src="https://agentmods.dev/badge/rules/tonyghiani/ai-essentials/react-refs-dom.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 660 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00660
Opus 5.5 $0.00000 $0.00264
Sonnet 5.5 $0.00000 $0.00132
Haiku 4.5 $0.00000 $0.00066

Measured 3mo ago against content hash 2778838d7e35, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

react-refs-dom scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/react-refs-dom.mdc · 66 lines

What it actually says

You are an expert React developer. When generating code that uses refs or manipulates the DOM, follow these rules.

Choosing Between State and Refs

  • Use state when:
    • The value affects what is rendered.
    • A UI update should occur when the value changes.
  • Use refs when:
    • The value does NOT affect the rendered output.
    • You need a mutable container that persists across renders without causing re-renders (e.g., timers, external instances, previous values, DOM nodes).

Accessing DOM Nodes

  • To access a DOM node:
    • Declare a ref: const inputRef = useRef<HTMLInputElement | null>(null).
    • Attach with ref={inputRef}.
    • Read or mutate inputRef.current only in:
      • Event handlers.
      • Effects.
  • Valid DOM ref use cases:
    • Focus management (element.focus()).
    • Scrolling (element.scrollIntoView()).
    • Measuring layout (getBoundingClientRect()).
    • Integrating non-React widgets and imperative libraries.

Rules for Using Refs

  • Do NOT read or write ref.current during render, except for idempotent lazy initialization:
    • Example: if (!ref.current) ref.current = createInstance().
  • Do NOT rely on ref.current changes to trigger UI updates. React does not re-render on ref changes.
  • Treat refs as implementation details:
    • Keep them inside components or custom hooks.
    • Avoid exposing them as primary APIs unless strictly necessary (e.g., forwardRef for focus-able components).

Lists and Collections of DOM Refs

  • Never call useRef inside loops, maps, or conditions.
  • For collections of DOM nodes:
    • Use a single useRef<Map<Key, HTMLElement | null>>(new Map()).
    • Use a ref callback to update the map:
      • On mount: map.set(key, node).
      • On unmount: map.delete(key).

Safe DOM Manipulation

  • Safe operations on DOM nodes owned by React:
    • Focus, scroll, reading layout, adding/removing event listeners.
  • Avoid destructive mutations of DOM nodes that React manages:
    • Do NOT manually remove, reparent, or deeply mutate React-owned elements.
  • When integrating third-party DOM code:
    • Prefer mounting it into a container that React treats as a black box (e.g., an always-empty div).
    • Do all manual DOM tree modifications within that container.

Refs in Custom Hooks

  • Encapsulate DOM-related refs in custom hooks when logic is reusable (e.g., useFocusOnMount, useIntersectionObserver).
  • Custom hooks may:
    • Create and manage refs internally.
    • Return refs to be attached to elements.
  • Keep custom hooks pure with respect to render; side effects must still be inside useEffect within the hook.
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 66 lines · 0 tokens per session scan A 2778838d7e35

Subscribe to this mod's changes

react-refs-dom is a cursor rule published in the GitHub repository tonyghiani/ai-essentials (7 stars, last pushed yesterday), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 660 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

react-refs-dom compared with cursor rules from other repositories

react-refs-dom next to 6 cursor rules from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
react-refs-domtonyghiani/ai-essentialsCursor rule7yesterdayMITA0Cursor
windsurfrulesAPIParkLab/APIParkCursor rule1.8k1mo agoApache-2.0A521Windsurf
backendtenstorrent/tt-studioCursor rule13todayApache-2.0A0Cursor
tanstack-start-guidejahands/promptsCursor rule191mo agoMITA17Cursor
new-componentkubev2v/forklift-console-pluginCursor rule11todayApache-2.0A6Cursor
tanstack-react-router_routingWebMCP-org/webmcp-shCursor rule181mo agoMITA17,188Cursor
rendering-and-memoizationgrafana/grafana-pathfinder-appCursor rule24todayAGPL-3.0A50Cursor