Some background of what I am attempting to do is that, my backend /content route returns an array with id data in it such as:
[12345,534543534,543543534,5435345435]
I am getting the array just fine and can see it in the browser when I console.log from the React component.
My question is this, I am trying to now map that date to a tag in the code. Here is the code:
import React, { useEffect, useState } from "react";
const Content = () => {
useEffect(() => {
async function getYouTubeList() {
try {
let url = "/api/content/";
let res = await fetch(url);
let data = await res.json();
return data;
// console.log(data);
} catch (err) {
console.error(err);
}
}
getYouTubeList();
}, [data]);
// const [data, setMyArray] = useState([]);
return (
<div>
<section className="content-landing">
<div className="dark-overlay">
<div className="content-landing-inner">
<h1>Content Archive</h1>
<p>
Enjoy some of my curated content from various
sources
</p>
<p>
<li>
<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/MAPTHEIDHERE"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
</li>
</p>
</div>
</div>
</section>
</div>
);
};
export default Content;
I am trying to map the "data" array that I return from the async function above the "return" portion into the tag where it says "MAPTHEIDHERE". I am not sure how to use the map function in this context and could use some references or help! Thank you all in advance!