question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migrate from findDOMNode to refs

See original GitHub issue

React team just finally announced deprecating findDOMNode.

https://github.com/facebook/react/pull/13841

Would be good to start providing better refs in each component to get rid from RootRef.

Edit @eps1lon: Hijacking OP to document progress.

If we need the DOM node we still use findDOMNode but we call it with refs. If the refs are attached to host components you won’t get a strict mode warning. Only if they are attached to class components.

Strict-mode ready findDOMNode

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
oliviertassinaricommented, Oct 12, 2018

This is such a big move from React. For a long time, I thought they weren’t going to execute on this. From what I understand, the motivation is around simplifying React internal core. This makes sense. Let’s see how we can fulfill this new constraint.

1reaction
eps1loncommented, Jun 15, 2019

Or do you mean that you don’t want yet another breaking change and for existing class components (that do not correctly forward refs) to work?

Yes. Just reducing the amount of breaking changes.

Is that because findDOMNode(validElementRef) is safe?

At least for now. We’re still waiting for an official confirmation but so far findDOMNode doesn’t throw if called with host instances.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrate React.findDOMNode to refs when rendering children
I'm dealing with a React component that uses React.findDOMNode(this) to obtain data about its position in the DOM, then it renders its ...
Read more >
Migrate from findDOMNode to refs #13221 - mui/material-ui
I believe this would be a breaking change. The API allows in many cases that users pass a custom root component. We still...
Read more >
Getting rid of findDOMNode in your React application - Medium
The simplest solution is to replace it with a ref attached to the element we are interested in referencing (or a wrapper of...
Read more >
Refs and the DOM - React
Refs provide a way to access DOM nodes or React elements created in the render ... with useImperativeHandle ), or you can convert...
Read more >
How to Use React.findDOMNode in TypeScript - Pluralsight
Simply attaching a ref callback to a particular DOM node should get you through all your required DOM manipulations smoothly. findDOMNode is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found