djankies/claude-configs/migrating-from-forwardref
Claude Code and agent skill by djankies/claude-configs
- community
Checking that the SKILL.md file is still in the repository.
Teaches migration from forwardRef to ref-as-prop pattern in React 19. Use when seeing forwardRef usage, upgrading React components, or when refs are mentioned. forwardRef is deprecated in React 19.
Install
npx vskill@latest install djankies/claude-configs/migrating-from-forwardrefSKILL.md
The same SKILL.md was published earlier as djankies/claude-configs/migrating-from-forwardref.
Migrating from forwardRef to Ref as Prop
<role> This skill teaches you how to migrate from the deprecated forwardRef API to React 19's ref-as-prop pattern. </role>
<when-to-activate> This skill activates when:
- User mentions
forwardRef, refs, or ref forwarding - Seeing code that uses
React.forwardRef - Upgrading components to React 19
- Need to expose DOM refs from custom components
- TypeScript errors about ref props
</when-to-activate>
<overview> React 19 deprecates forwardRef in favor of ref as a regular prop:
Why the Change:
- Simpler API - Refs are just props, no special wrapper needed
- Better TypeScript - Easier type inference and typing
- Consistency - All props handled the same way
- Less Boilerplate - Fewer imports and wrapper functions
Migration Path:
forwardRefstill works in React 19 (deprecated, not removed)- New code should use ref as prop
- Gradual migration recommended for existing codebases
Key Difference:
</overview>
<workflow>
Migration Process
Step 1: Identify forwardRef Usage
Search codebase for forwardRef:
Step 2: Understand Current Pattern
Before (React 18):
Step 3: Convert to Ref as Prop
After (React 19):
Step 4: Update TypeScript Types (if applicable)
Before:
After:
Step 5: Test Component
Verify ref forwarding still works:
</workflow>
<conditional-workflows>
Complex Scenarios
If component uses useImperativeHandle:
Before:
After:
If component has multiple refs:
If using generic components:
</conditional-workflows>
<progressive-disclosure>
Reference Files
For detailed information:
- Ref Cleanup Functions: See
../../../research/react-19-comprehensive.md(lines 1013-1033) - useImperativeHandle: See
../../../research/react-19-comprehensive.md(lines 614-623) - TypeScript Migration: See
../../../research/react-19-comprehensive.md(lines 890-916) - Complete Migration Guide: See
../../../research/react-19-comprehensive.md(lines 978-1011)
Load references when specific patterns are needed. </progressive-disclosure>
<examples>
Example 1: Simple Button Migration
Before (React 18 with forwardRef):
After (React 19 with ref prop):
Changes Made:
- ✅ Removed
forwardRefimport - ✅ Removed
forwardRefwrapper - ✅ Added
refto props destructuring - ✅ Removed unnecessary
displayName - ✅ Simplified function signature
Example 2: TypeScript Component with Multiple Props
Before:
After:
Changes Made:
- ✅ Changed import from
forwardReftoReftype - ✅ Added
ref?: Ref<HTMLDivElement>to interface - ✅ Removed
forwardRefwrapper - ✅ Added
refto props destructuring - ✅ Removed
displayName
Example 3: Input with useImperativeHandle
Before:
After:
Usage (unchanged):
Example 4: Component Library Pattern
Before:
After:
</examples>
<constraints>
MUST
- Add
refto props interface when using TypeScript - Use
Ref<HTMLElement>type from React for TypeScript - Test that ref forwarding works after migration
- Maintain component behavior exactly (only syntax changes)
SHOULD
- Migrate components gradually (forwardRef still works)
- Update tests to verify ref behavior
- Use consistent prop ordering (ref near other element props)
- Document breaking changes if part of public API
NEVER
- Remove
forwardRefif still on React 18 - Change component behavior during migration
- Break existing ref usage in parent components
- Skip TypeScript type updates for ref prop
</constraints>
<validation>
After Migration
- Verify Ref Forwarding:
``javascript const ref = useRef(null); <MyComponent ref={ref} /> // ref.current should be the DOM element ``
- Check TypeScript Compilation:
``bash npx tsc --noEmit `` No errors about ref props
- Test Component Behavior:
- Component renders correctly
- Ref accesses correct DOM element
- useImperativeHandle methods work (if used)
- No console warnings about deprecated APIs
- Verify Backward Compatibility:
- Existing usage still works
- No breaking changes to component API
- Tests pass
</validation>
Migration Checklist
When migrating a component from forwardRef:
- [ ] Remove
forwardRefimport - [ ] Remove
forwardRefwrapper function - [ ] Add
refto props destructuring - [ ] Add
reftype to TypeScript interface (if applicable) - [ ] Remove
displayNameif only used for forwardRef - [ ] Test ref forwarding works
- [ ] Update component tests
- [ ] Check TypeScript compilation
- [ ] Verify no breaking changes to API
Common Migration Patterns
Pattern 1: Simple Ref Forwarding
Pattern 2: With useImperativeHandle
Pattern 3: TypeScript with Generics
For comprehensive forwardRef migration documentation, see: research/react-19-comprehensive.md lines 978-1033.
Ref Cleanup Functions (New in React 19)
React 19 supports cleanup functions in ref callbacks:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingreact-19/skills/migrating-from-forwardref/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/djankies/claude-configs/migrating-from-forwardref)