findDOMNode
Returns the browser DOM node corresponding to a React component instance.Reference
findDOMNode(componentInstance)
Call findDOMNode to find the browser DOM node for a given React component instance.
/src/client/ReactDOMClient.js:43-47
Parameters
React.Component
required
An instance of a React component (typically
this from a class component).Returns
Element | Text | null
The browser DOM node corresponding to the component. Returns
null if the component rendered null or false.Why Is It Deprecated?
findDOMNode has several problems:
- Breaks abstraction - Reaches into component internals
- Only works with class components - Not compatible with function components
- Returns first child only - Confusing with fragments
- Prevents optimizations - React can’t optimize as much
- Breaks with Strict Mode - Causes issues in concurrent rendering
Migration Timeline
- React 16.3:
findDOMNodedeprecated - React 17: Warning in Strict Mode
- React 18: Stronger warnings
- Future: Will be removed entirely
Migration Guide
Pattern 1: Forwarding Refs
Before (with findDOMNode):Pattern 2: Direct Refs
Before (with findDOMNode):Pattern 3: Measuring Elements
Before (with findDOMNode):Pattern 4: Event Listeners
Before (with findDOMNode):Pattern 5: Third-Party Library Integration
Before (with findDOMNode):Common Scenarios
Focus Management
Scrolling to Element
Animation
TypeScript
Testing
When You Might Still See It
You might encounterfindDOMNode in:
- Legacy codebases - Old React code not yet migrated
- Third-party libraries - Older libraries still using it
- React Native - Different implementation, not deprecated there
Best Practices
- Use refs instead - Modern, performant, and future-proof
- Forward refs when needed - For component composition
- Use useImperativeHandle - For exposing imperative methods
- Avoid DOM manipulation - Let React manage the DOM
- Migrate legacy code - Update
findDOMNodeusage proactively
Related APIs
- useRef - Create refs in function components
- forwardRef - Forward refs through components
- useImperativeHandle - Customize ref values
- createRef - Create refs in class components