2

I have react component that renders something like:

<div>
    <div key='bowie'>something</div>
<div>

when I query the keys of each node (using enzyme if that matters), my keys are printed as

.$bowie

Is the .$ something I can rely on? What does it mean?

brendangibson
  • 2,377
  • 2
  • 21
  • 36

1 Answers1

1

It is not something you can rely on. The key attribute does not give any public API beside the original assignment, and the value is only used internally to improve the rendering/diffing algorithm.

React v15+ actually removed the data-reactid attribute (I'm assuming this is where you are seeing the keys?) from the DOM entirely, since it now uses internal references. More on that in the React 15 release blog post.

As far as the importance of the $ itself, I'm not sure, but I would guess that it made it easier to parse the IDs.