ref-patterns
CommunityUse refs for DOM access without breaking React.
Authorjacob-balslev
Version1.0.0
Installs0
System Documentation
What problem does it solve?
This Skill prevents common React ref misuse by helping you choose refs over state when you need a stable mutable handle for DOM access, measurement, focus, animations, third-party integration, or a narrowly-scoped imperative API.
Core Features & Use Cases
- Ref vs state decision-making: explains when a changing value should drive rendering (state) versus when it should not trigger renders (ref).
- useRef patterns: covers DOM refs and mutable instance values that persist across renders (e.g., interval ids, latest-args closures, previous-value snapshots).
- Ref callback patterns: uses
ref={(node) => ...}for precise mount/unmount hooks and conditional attachment/composition. - Ref propagation across component boundaries: teaches
forwardRef(legacy/new options), and React 19 ref-as-prop for passing refs into function components. - Controlled imperative APIs: uses
useImperativeHandleto expose only the minimal methods a parent truly needs. - Compound-component ref forwarding: ensures primitives forward refs through layers (e.g., Radix Slot-style merge) so consumer focus/measurement works.
- Client/Server boundary constraints: clarifies why refs require Client Components and cannot be created/passed across Server boundaries.
Quick Start
Use the ref-patterns skill to design a React component that forwards a ref safely (including compound-component cases) and uses useImperativeHandle only when imperative control is truly required.
Dependency Matrix
Required Modules
None requiredComponents
Standard package💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: ref-patterns Download link: https://github.com/jacob-balslev/skill-graph/archive/main.zip#ref-patterns Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.