Correct use of DOM with React.js

Asked

Viewed 646 times

5

Knowing that Reactjs uses a virtual DOM where elements are processed into a DOM representation in memory so that all changes are made faster then it would be "wrong" to use findDOMNode to directly access an DOM element and manipulate its state?

1 answer

6


Yes, it would be wrong.

findDOMNode only exists for reading DOM information (eg: position, form fields value, etc). Modify the DOM directly can also generate inconsistencies, because the view that the framework has the DOM (virtual-dom) will not be the same as DOM in the browser, then it may end up overwriting the values you manually set.

  • 1

    So just to be clear, with respect to getting the value of an input text the most correct way would be findDOMNode? Because the first tests I’ve been doing with React I was doing a bigger gambiarra in the world with events not to access the DOM directly.

  • 1

    Nice surprise to see you here @fabiomcosta!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.