Hi! How can you add custom attributes to react htm...
# javascript
r
Hi! How can you add custom attributes to react html elements? I have the same question posted here: https://stackoverflow.com/questions/73690252/adding-custom-data-attributes-to-tags-while-using-the-newnon-legacy-kotlin-r
t
Default solution - extensions
Copy code
private const val DATA_SELECTED: String = "data-selected"

var HTMLAttributes<*>.dataSelected: Boolean
    get() = asDynamic()[DATA_SELECTED]
    set(value) {
        asDynamic()[DATA_SELECTED] = value
    }
👍🏾 1
r
Many thanks @turansky ! I posted this answer in the slack question as well.