Reason behind the preference of callback refs over findDOMNode()

  • findDOMNode() is deprecated in the StrictMode. It may be removed from the react in its future updates. So if we still want to use findDOMNode() then we shouldn’t place our App Component in “React.StrictMode” within index.js
  • We shouldn’t use findDOMNode() because if it gets deprecated from the react in its future version, then again we have to replace that with refs/callback refs, which will take extra effort.
  • According to React docs findDOMNode() only accepts instance of class component.That’s why it can’t be used with the functional components.


Which is preferred option with in callback refs and findDOMNode() in ReactJS ?

ReactJS employs two prominent concepts, namely callback refs and `findDOMNode()`, for effective DOM manipulation. These mechanisms facilitate access to DOM elements, enabling the implementation of diverse changes such as hiding or showing elements, altering styles, and focusing on specific elements.

Table of Content

  • findDOMNode()
  • Callback refs

Similar Reads

Prerequisites:

Node JS or NPM React JS Callback refs findDOMNode()...

Steps to Create React Application And Installing Module:

Step 1: Create a react application using this command:...

findDOMNode():

findDOMNode() was very popular for returning the DOM of any element in the class-based component. But after React v16.3 it was discouraged but till now it is used for certain use cases. But there is a chance that it might get removed from the future version of React....

Callback refs:

...

Reason behind the preference of callback refs over findDOMNode():

Callback refs stand out as a crucial concept in ReactJS for DOM manipulation. When manipulating the DOM using refs, we pass a ref, created with “React.createRef” in class components and “useRef” in functional components, directly to the element to gain access to it....

Contact Us