html - How to add data attribute without value in react create element? -
i adding div
dom below,
react.createelement("div", { classname: "test"});
the rendered html should below
<div class="test" data-test> </div>
where can add data-test
in createelement
?
you can't because attribute without value means attribute has value true
in jsx. don't pass data-test
, this.props['data-test']
undefined in component. or if need have attribute empty value add default values in component definition.
defaultprops: { 'data-test': '' }
Comments
Post a Comment