Ad

How Can A String Be Added To React JSX Div Id?

I would like to change id of a div in jsx like so :-

{ ['A','B','C','D'].map((element, cell) => (
    <div id="alphabet_{element}">
        Some
    </div>
)) } 

But this results in

<div id="alphabet_{element}">
    Some
</div>

How can I get the actual value of {element} in my div id?

Ad

Answer

try this:

{ ['A','B','C','D'].map((element, cell) => (
    <div id={`alphabet_${element}`}>
        Some
    </div>
)) } 
Ad
source: stackoverflow.com
Ad