Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Data Fetching in Next.js

Let's say I wanted to fetch data from a website, and the link to that website is http://cookiestats.net/cookies, and the data on that link is this:

{"cookie-stats": {"eating": 1, "eaten": "6"}, "people-eating": {"current": 3, "total": "6"}}

What am I doing wrong?

export const getStaticProps = async () => {
    const res = await fetch('http://cookiestats.net/cookies');
    const data = await res.json();
    
    return{
        props: {cookies: data}
    }
}

const Cookies = ({ cookies }) => {
    return (
        <div>
            <h1>Cookie Data</h1>
            {Object.keys(cookies).map(cookies => (
                <div key = {cookies.cookie-stats}>
                    <a>
                        <h3>{cookies.eating}</h3>
                    </a>
                    </div>
            ))}
        </div>
    );
}

export default Cookies;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are trying to map an object which is not possible. Instead you could try to use the method Object.keys:

 Object.keys(cookies).map(cookiesKey => (
     <div key = {cookies[cookiesKey]}>
         <a>
            <h3>{cookies[cookiesKey]}</h3>
         </a>
     </div>
 ))}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!