If I write this in JSX and render it with React:
<div data-foo>Hello world</div>
...the resulting DOM looks like this:
<div data-foo="true">Hello world</div>
Why?
For comparison, when I use standardised boolean attributes (e.g. <button disabled>OK</button>), this doesn't happen – the resulting DOM is the same as the JSX. Why are boolean data-attibutes treated differently?
data-attribute. They're strings as far as the DOM is concerned.data-attributes, but for example the jQuery.data()API checks to see if the attribute value can be interpreted as JSON, and if so you get back the result of a JSON parse, and in the case of strings that look like JavaScript primitives (numbers and booleans) you get the parsed primitive value.