X
X
xXRustamXx2018-11-25 01:53:18
React
xXRustamXx, 2018-11-25 01:53:18

Is it possible to use findDOMNode and querySelectorAll in React?

Faced with the task of removing all classes in certain components of an element, and adding an active class to the current element of the current component, since there is no access to other elements through ref due to the fact that they are in different components, I do this as follows:

let titles = ReactDOM.findDOMNode(this).parentNode.parentNode.querySelectorAll('.wrp_desk_title textarea');
    titles.forEach( item => {
      item.classList.remove('title_active');
    });

To what extent is this a normal option and is it generally possible to do this, if not, what alternatives are there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2018-11-25
@xXRustamXx

This approach is very much contrary to the canons of react. No need to access the nodes unless absolutely necessary (usually this is a call to the methods of the input nodes). Use the parent state.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question