Sometimes, we want to add custom HTML attributes in React.
In this article, we’ll look at how to add custom HTML attributes in React.
Add Custom HTML Attributes in React
To add custom HTML attributes in React, we can just add them as we do with regular HTML element attributes.
For instance, we can write:
import React from "react";
export default function App() {
return <div custom-attribute="some-value" />;
}
We just add the custom-attribute
custom attribute and it’ll be rendered in the HTML.
This works since React 16.
Conclusion
To add custom HTML attributes in React, we can just add them as we do with regular HTML element attributes.