I’m working on a streaming dashboard in Next.js that pulls data from multiple gaming platform endpoints. Everything works great except for one specific map function that’s driving me crazy.
I can see all the data perfectly when I console.log it, but nothing shows up on the actual page. The other mapping functions work fine and display their content without issues. I’m still pretty new to working with APIs but I really want to get this project working.
Has anyone run into this before? I’ve been stuck on this for hours and could really use some help!
// pages/StreamDash/index.js
import fetch from "node-fetch";
import {
Container,
Title,
Separator,
Paragraph,
Card,
Label,
Grid,
Avatar,
Wrapper,
Stack
} from "@ui/components";
import { getAuth } from "next-auth/react"
import React, { useState } from "react"
import { BsPlay } from 'react-icons/bs'
const Dashboard = ({ LiveStreams, ApiKey, Profile }) => {
const [keyVisible, setKeyVisible] = useState(false);
const showApiKey = () => setKeyVisible(true);
const hideApiKey = () => setKeyVisible(false);
if (!Dashboard) {
return <div>Loading streams...</div>;
}
return (
<>
<Container>
{Profile?.map((profile) => (
console.log(Profile),
<Card key={profile.id}>
<Grid>
<Title padding="4">{profile.username}</Title>
<Label
size="md"
variant="primary"
>Total Views: {profile.total_views}
</Label>
</Grid>
</Card>
))}
{ApiKey.map((secret) =>(
<div key={secret.id}>
<button onClick={showApiKey}>Reveal Key</button>
<button onClick={hideApiKey}>Hide Key</button>
{keyVisible ? <span>{secret.api_key}</span> : null}
</div>
))}
</Container>
<Wrapper>
<Card maxWidth="sm">
<Stack padding={6}>
{LiveStreams.map((stream) => { // Problem is here
console.log(LiveStreams), // Console shows correct data
<div key={stream.id}>
<span>{stream.broadcaster_name}</span> // Nothing renders here
<Title variant="bold" size="xl">
{stream.broadcaster_name}
</Title>
<Paragraph color="muted">
{stream.game_name}
</Paragraph>
</div>
})}
</Stack>
{LiveStreams.map((stream) => {
<div key={stream.id}>
<Avatar
height={32}
width="full"
src={stream.preview_image}
alt="Live stream preview"
/>
<Grid>
<Title color="white" weight="bold">
{stream.current_viewers}
</Title>
<button className="watch-btn">
Watch Now
</button>
</Grid>
</div>
})}
</Card>
</Wrapper>
</>
);
};
Dashboard.getInitialProps = async (ctx) => {
try {
const auth = await getAuth({
req: ctx.req,
});
const liveData = await fetch(
`https://api.platform.tv/v1/streams/live?user_id=${auth.userId}`,
{
headers: {
"Authorization": `Bearer ${auth.token}`,
"Client-Id": `${process.env.PLATFORM_CLIENT_ID}`,
},
}
);
const keyData = await fetch(
`https://api.platform.tv/v1/user/key?id=${auth.userId}`,
{
headers: {
"Authorization": `Bearer ${auth.token}`,
"Client-Id": `${process.env.PLATFORM_CLIENT_ID}`,
},
}
);
const userData = await fetch(
`https://api.platform.tv/v1/users/${auth.userId}`,
{
headers: {
"Authorization": `Bearer ${auth.token}`,
"Client-Id": `${process.env.PLATFORM_CLIENT_ID}`,
},
}
);
const LiveStreams = liveData.data.results;
const ApiKey = keyData.data.results;
const Profile = userData.data.results;
return { LiveStreams, ApiKey, Profile };
} catch (err) {
console.log(err);
return <div>Error: {err.message}</div>;
}
};
export default Dashboard;