I'm using map() to iterarate an array of objects to render them on my app. I have imported audio files and I would like to reference them for the src
attribute when mapping. src={x.sound}
evaluates to just text, as it should. How can I achieve something like this src={{x.sound}} => src={boom}
so that the src
would actually be a valid path after iteratively rendering?
Thank you!
import boom from "./sound/boom.ogg";
const data = [
{
key: "Q",
keyCode: 81,
sound: "boom",
},
];
const buttons = () =>
data.map((x) => (
<div
onClick={this.clickHandle}
id={x.sound}
className="drum-pad"
key={x.key}
>
{x.key}
<audio
id={x.key}
key={x.key}
src={x.sound}
className="clip"
controls
></audio>
</div>
));