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

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -