My CMS outputs a string of data attributes to add to an element I wanted to know how I can add the string of attributes to an element in React
This sample code does not appear to work.
function HelloWorld(props) {
const fromCMS = `data-target="h1" data-content="Hello World"`;
return (
<h1 {fromCMS}>{props.content}</h1>
)
}
Try this one.
const fromCms = {"data-target": "h1", "data-content": "Hello World"}
...
<h1 {...fromCMS}>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With