react-useref

Explain and demonstrate the four primary use cases of the React useRef hook.

Updated Feb 28, 2026
One-click install
npx skills add https://github.com/b4r7x/agent-skills --skill react-useref
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-useref
Source: https://github.com/b4r7x/agent-skills/tree/main/react-useref
Command: npx skills add https://github.com/b4r7x/agent-skills --skill react-useref

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill clarifies the appropriate use of useRef in React, distinguishing it from useState and demonstrating its application for DOM manipulation, mutable value storage, and integration with external libraries, while also highlighting modern alternatives like useEffectEvent.

Core Features & Use Cases

  • Distinguish useRef vs. useState: Understand when to use useRef (no re-render on change) versus useState (re-render on change).
  • DOM Access: Imperatively interact with DOM elements (e.g., focusing inputs, measuring elements).
  • Mutable Values: Store values that persist across renders without triggering UI updates (e.g., timer IDs, previous values, first render flags).
  • External Libraries: Integrate with non-React libraries that require direct DOM manipulation.
  • Modern React 19.2+: Understand the replacement of the useRef workaround for stable callbacks with useEffectEvent.

Quick Start

Use the react-useref skill to understand how to access a DOM input element using a ref.

Frequently Asked Questions about react-useref

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When should I use useRef instead of useState in React?

Use the useRef hook when you need to store mutable values that persist across renders without triggering UI re-renders, unlike useState which causes a component to update upon value change.

How do I access a DOM element for input focus or measuring in React?

Access a DOM element by attaching a ref object to it, allowing imperative interactions like focusing inputs or measuring elements directly without relying on state-driven re-renders.

Can I use useRef to integrate external JavaScript libraries with React?

Yes, useRef can integrate non-React external JavaScript libraries by providing a stable reference to a DOM node, enabling direct DOM manipulation required by those libraries.

Does React 19.2 provide an alternative to useRef for stable callbacks?

Yes, React 19.2 introduces useEffectEvent as a modern replacement for the useRef workaround, specifically designed for handling stable callbacks without causing unnecessary re-renders.

Why does changing a ref value not update my React component UI?

Changing a ref value does not update the UI because useRef is designed for mutable storage that bypasses the React render cycle, ensuring no re-render is triggered when the value changes.