Encountering issue with API request in NextJs: "Error message - 'banner.map is not a function'"

After following a tutorial that demonstrated how to request data from an API and display it, I encountered an issue when trying to view the page in my NextJs project. The error message "banner.map is not a function" appeared. Below is the code snippet where the problem occurs. Any assistance would be greatly appreciated. The API being called is "https://fortnite-api.com/v1/banners", which returns an array of objects.

    export const getStaticProps = async () => {

    const res = await fetch('https://fortnite-api.com/v1/banners');
    const data = await res.json();

    return {
        props: { banners: data}
    }

}

const FortniteApi = ({ banners }) => {
    return (
        <div>
            <h1>Fortnite Api</h1>
            {banners.map(banner => (
                <div key={banner.id}>
                    <a>
                        <h3>{banner.name}</h3>
                    </a>
                </div>
            ))}
        </div>
    )
}

export default FortniteApi

Answer №1

In order to access a different object data within the function:

return {
  props: { images: data },
};

INSTEAD,

return {
  props: { images: data.images },
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide to extracting data from dynamic html table rows with jQuery

function AddRow() { $('#myDynamicTable tr:last').after('<tr><td class="itemName"><input type="text" style="width: 300px;"/><td class="itemQty"><input type="text" style="width: 50px;"/></td></td> ...

Controlling Formatting in ASP.NET

Feeling puzzled by a seemingly simple question with no clear solution in sight. We're attempting to transition an interface to an ASP.NET control that currently appears like this: <link rel=""stylesheet"" type=""text/css"" href=""/Layout/CaptchaLa ...

Tips for creating a drawing grid with a table

I am currently working on a project where I need to create a canvas-like table with around 10,000 cells. The goal is to allow users to draw on this canvas by moving their mouse over it while holding down specific keys (e.g. ctrl for blue, shift for red). ...

"Revolutionize real-time data updates with Node.js, Redis, and Socket

Greetings! I am currently working on a project for my school that involves creating a "Twitter clone." My goal is to incorporate a publish subscribe pattern in order to facilitate real-time updates. One key feature users will have access to is the abili ...

The AngularJS script is throwing an error that states "ReferenceError: Invalid left-hand side in assignment

While attempting to establish a connection with a webservice, I made an attempt using AngularJS $http option. However, when testing it out, I encountered an error in the console of my Chrome browser: ReferenceError Invalid left-hand side in assignment. Des ...

What is the most efficient method of converting an object into a list without resorting to a double for loop?

Within my code, there is an object named 'times' which contains another object labeled '20102'. This inner object has a collection of three sub-objects structured like so: times: { 20102: [ { name:'jane', age:12 }, ...

Which modal popup option is best: ASP.NET AjaxControlToolkit, jQuery plugin, or Greybox?

In my ASP.NET web forms application, I am in need of a modal popup that can present users with a preview of images based on their search criteria. For example, if they search for "dog," the popup should display all dog-related pictures. The search results ...

How can you convert a string to a boolean in Javascript?

Any tips on converting the options.isdedicated to a boolean value of true or false rather than a string? <?php $isdedicated = file_get_contents("/home/www/html/config.ini"); //echoed true?> <script> var options = []; options.isdedicated ...

Issue with Mongoose Express API failing to retrieve information from req.body

Currently in the process of developing the backend for an application using MongoDB (Mongoose) and Express. While working on the API, I encountered an issue with POST requests to /movies where no data from req.body is being submitted. When testing with dum ...

Ways to eliminate or conceal solely the play/pause symbol or button from the media player within the video tag

[Please see the screenshot attached, I am looking to remove the play/pause icon that is highlighted] [screenshot] How can I hide or remove only the play/pause button from the media player of a video tag? When I dynamically add the controls attribute using ...

The concept of "Fetch" is not compatible with both Firebase and Jest

Having some difficulty running tests with jest on my Next.js project as I keep encountering the following error: src/lib/utils/item.utils.test.tsx ● Test suite failed to run ReferenceError: fetch is not defined 32 | export const firebaseCo ...

What could be causing the malfunction in the app due to the GraphQL input type?

I encountered a challenge while testing a mutation on an Apollo GraphQL API. Initially, everything was working fine as I utilized individual fields for the mutation type. However, as soon as I replaced these fields with the input type that I had created, a ...

Ajax polling ceases the polling process when an internet connection is lost

My current setup involves a continuous ajax polling cycle where messages are pulled, processed, a wait period occurs, and then the process is repeated. Everything runs smoothly until a user disconnects from the internet, whether it be due to a simple actio ...

Tips on using JQuery to extract form field information from a drop-down menu, display it in a div, and then compare it with the subsequently

In my HTML file, I am using two dropdown lists and JQuery for validation. First, I need to save the selected items from both dropdown lists in a variable and then compare them with the next selection. If the data from both dropdown lists match, an alert m ...

How do you trigger the playback of a specific audio file when a user clicks on it?

I'm currently working on an interactive music app that mimics the functionality of a piano. Users are able to click on different boxes on the screen, triggering a unique musical note to play. While I initially considered manually collecting all the I ...

Gremlin, can you tell me where the "valueMap()" function has been imported from in JavaScript?

Working with ES6 on Node.js, I am attempting to execute the project() step within a Gremlin query. For this projection, my goal is to extract the properties. In the Gremlin console, I would typically use valueMap() to retrieve these properties. However, ...

Tips for achieving printing with the "Fit sheet on one page" option in JavaScript

Is there a way to print a large table of data with 200 or 300 rows all on one page, similar to the Online MS Excel print option 'Fit Sheet on One Page'? I attempted the code below: var tble = document.createElement("table"); tble.id = "tble"; d ...

Having trouble installing Bootstrap using the `npm i bootstrap` command? It seems like the

The npm i bootstrap command is not working when trying to install Bootstrap. Nothing is being added to the packages.json file or node_modules directory. Here are the dependencies listed in the package.json file: "dependencies": { "@angu ...

Stripe AxiosError: The request was unsuccessful due to a status code of 500

Currently, I am attempting to integrate Stripe checkout into my NextJS project by referring to this example. However, I consistently encounter the following error: https://i.sstatic.net/ri1nQ.png The issue arises in my checkout.js file: import React ...

Initiate the month transition event within the fomantic calendar

In my project, I have integrated the fomantic calendar and it is working properly. However, I am facing an issue when it comes to changing the month. Is there a specific event for month changes in the fomantic calendar? I am struggling to make it work. Tha ...