![]() |
VOOZH | about |
findDOMNode in React is used to directly access a component's underlying DOM node. It is mainly used in class components for DOM manipulation, animations, or integration with third-party libraries. It's considered unsafe in modern React development.
ReactDOM.findDOMNode(component)Parameters:
Return Value:
The findDOMNode() method returns the DOM node associated with the specified React component or null if the component is not mounted.
Step 1: Create a React application using the following command.
npx create-react-app foldernameStep 2: After creating your project folder i.e. foldername, move to it using the following command.
cd foldernameIt will look like the following.
👁 ImageExample: A React component that changes the style of a specified DOM element when a button is clicked using findDOMNode().
Step to Run Application: Run the application using the following command from the root directory of the project:
npm startOutput: Now open your browser and go to http://localhost:3000/, you will see the following output:
👁 ImageReference:
https://legacy.reactjs.org/docs/react-dom.html#finddomnode