Inserting variables and constants into tag attributes in JSX
Variables and constants can be inserted not only into tag texts, but also into attributes. In this case, quotation marks are not placed around attributes:
function App() {
const str = 'elem';
return <div id={str}>
text
</div>;
}
The result of running this code will be the following:
<div id="elem">
text
</div>
The following code is given:
function App() {
const attr = 'block';
return <div>
text
</div>;
}
Insert the value of the constant attr
into the id
attribute of our div.