What does the data-react attribute mean?

3

I was looking at some sites on the internet, and I saw, in the source code of some pages, an attribute called data-reactid , inserted in elements div .

What is this attribute, what is its function and what does it influence?

    
asked by anonymous 17.04.2017 / 22:36

2 answers

3

This data-reactid is a data- HTML attribute used by React to interact with the DOM. React creates a virtual DOM, a collection of arrays and objects that it handles internally to avoid changing the DOM if it is not needed.

Since most interaction with an application is a change of values and actions that do not need to be in the DOM, react leaves a "port", a pointer, for each element through that data-reactid . So, when it is time to change something in the DOM, the element has an attribute to be referenced.

I'm not sure if this is useful in debug, if React saves this data-reactid to look it up in the DOM or if it's just to mirror what goes on inside. I imagine for debug and show what goes on internally, and the virtual DOM have references to the object / element in question.

    
17.04.2017 / 22:57
0

It belongs to the Framework React and is automatically added by the Framework itself, to identify some component, in order to perform some updating and / or manipulation of content.

This method, however, was used in earlier versions. As of version 15, according to the #, this attribute is no longer used, instead of data-reactid you may notice some other attributes like data-reactroot or even comments such as <!-- /react-text: 2 --> .

    
17.04.2017 / 22:41