I have some data returning from an API, and I'm trying to create a template to return a carousel with the images/headers/descriptions already formatted. When I return these, they always have undefined prefixed to them, and they are still strings. I tried using dangerouslySetInnerHTML with String.raw`${x}` , which worked for something else, but this also doesn't render them as proper HTML. I'll paste my code below, any advice or guidance is appreciated.
export function CarouselImages({ projTitle, uid }) {
const [json, setJson] = useState({});
useEffect(() => {
get_slide_data(projTitle).then(setJson).catch(console.error);
}, [projTitle]);
console.log(json.TheMovieDBAPI);
let Indicators = () => {
let temp;
for(let i in json.TheMovieDBAPI){
if(i == 1){
temp += `<button type="button" data-bs-target=${uid} data-bs-slide-to=${(i-1)} className="active" aria-label=${"Slide " + (i)} aria-current="true"></button>`
}else{
temp += `<button type="button" data-bs-target=${uid} data-bs-slide-to=${(i-1)} className="" aria-label=${"Slide " + (i)} aria-current="true"></button>`
}
}
return temp;
};
let Slides = () => {
let temp;
for(let i in json[projTitle]){
temp += `<div class="carousel-item active">
<img src=${i.src} class="d-block">
<div class="carousel-caption d-none d-md-block">
<h5 class="h5">${i.heading}</h5>
<p>${i.desc}</p>
</div>
</div>`;
}
return temp;
};
console.log(Indicators);
return (
<div className="carousel slide projImg py-2" id={uid} data-bs-ride="carousel">
<div className="carousel-indicators">
<Indicators />
</div>
<div className="carousel-inner">
<Slides />
</div>
</div>
)
}