What is the reason for not displaying the various li elements on my webpage?

Here is the code snippet

export default function DisplaySearchResults({ results }) {
    var arr = Object.entries(results)
    console.log(arr)
    return (
      <div>
        Here are the search results :
        <ol>
            {arr.map((value, index) => {
                <li key={index}>{value.title}</li>
            })}
        </ol>
      </div>
    );
  }
  
  export async function getServerSideProps({ params }) {
    const { id } = params;
  
    const response = await fetch(
      `http://localhost:4000/data/${id}`
    );
    const results = await response.json();
  
    return {
      props: { results } // will be passed to the page component as props
    };
  }

At this point:

console.log(arr)

This line prints an array with 100 subarrays retrieved from the API...

The data in the array looks like this:

[["0", {title: "I like pizza", textValue: "Yes, I do"}], ["1", {title: "I like burgers", textValue: "Yes, I do"}]]

However, on the page, only an empty list <ol></ol> is displayed with no content inside.

I am currently trying to determine the reason behind this issue...

Answer №1

To fix the issue, make sure to return the map function and check for any errors in your console such as:

An error indicating the need to return a value in arrow function. (array-callback-return)

return (
  <div>
    Here's what you should do :
    <ol>
        {arr.map((value, index) => ( //<--return items
            <li key={index}>{value.title}</li>
        ))}
    </ol>
  </div>
);

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

How can Sass be properly integrated into a NextJs project?

When incorporating Sass files in my NextJs project, I keep encountering 'conflicting order' warnings from the mini-css-extract-plugin. This conflict consistently disrupts my styles during the build process. The specific error is elaborated on in ...

What steps can I take to stop the textfield from automatically changing the ID "myid" to "myid-tokenfield" when using Tokenfield for Bootstrap?

While utilizing Tokenfield for Bootstrap, I have encountered an issue where the id of my textfield gets modified from myid to myid-tokenfield. In order to properly interact with the search engine I am using, this textfield must maintain a specific id. The ...

Activate the q-file toggle for the Quasar framework when a different button is selected

How can I make the file selector q-file toggle in Quasar framework when a specific button is clicked? My current attempt: When this button is clicked, it should toggle the q-file: <button @click="toggleFileSelector">Toggle File Selector&l ...

Removing unwanted symbols from React router URLsLearn how to clean up unnecessary characters in your React router URLs

When using react-router I pass a parameter in the route like this: <Router> <Route path="/home/item/:item" component={Main} > <IndexRoute component={Home} /> <Route path="signing" component={Signin} /> </Route ...

How to efficiently eliminate duplicates from an array list using React framework

Keeping the array name constant while duplicating and repeating this process only clutters the list. Appreciate your help. setListItems(contents.data); console.log(contents.data); ...

Ways to alter the appearance of individual characters in the text input

My latest project involves dynamically changing the CSS styles of each individual character in a given text input. For example, if the user types "Stack" into the input field, I want the 'S' to appear in red, 't' in blue, 'a' ...

How can I retrieve the value of a specific JSON attribute in Cloud Functions?

Inside the text box for my pubsub message, there is a json file that appears like this: { "message": "Good morning", "sender": "Joe Schmoe" } I've made several attempts to retrieve the value of "sender", but have been unsuccessful in the following w ...

Error encountered in Azure DevOps pipeline: ##[warning] Debug log for JsNode not found in the cache or working directory

When attempting to upload my JS app into Azure DevOps, I encountered an error during the running pipeline at the NPM build stage. It seems like there is a debug log missing in the cache or working directory, causing the NPM build to fail. Did anyone else ...

The nodejs alpine docker image does not support exporting

I'm trying to set up a http_proxy environment variable in the nodejs alpine docker image. This is how the Dockerfile is configured FROM node:6-alpine RUN export RUN export https_proxy='http://myproxy:8080' RUN export http_proxy='http ...

React.js - keeping old array intact while using array map

I am currently experiencing an issue where I have two arrays, and I need to map through one of the arrays when navigating the page. However, instead of replacing the old array with the new one, it is just keeping the old array and adding the new one. Here ...

Tips for importing a module such as 'MyPersonalLibrary/data'

Currently, I am developing a project with two packages using Typescript and React-Native: The first package, PackageA (which is considered the leaf package), includes a REST client and mocks: MyOwnLibrary - src - tests - mocks - restClientMoc ...

Unable to modify the name of an element's class due to restrictions in JavaScript

I am trying to switch the class of an element from score -box1 to score -box1.-active. I defined a constant $target in order to access the class score -box1, however it is not functioning as expected. const $target = document.getElementByClassname('sc ...

Exploring ways to expand the theme.mixins feature in MUI 5

Currently, I am in the process of updating Material UI from version 4 to 5 and encountering challenges with my existing theming. Since we are using typescript, it is important to include the appropriate types when extending themes. I intend to include th ...

Guide on accessing js file in an Angular application

I have a component where I need to create a function that can search for a specific string value in the provided JavaScript file. How can I achieve this? The file path is '../../../assets/beacons.js' (relative to my component) and it's named ...

Dispatching information to a designated Google Analytics tracking code

Within our website, we have a unique dimension that is configured on Google Analytics and utilized when sending the page view event: gtag('config', 'UA-TrackingCode', { 'custom_map': { 'dimension1': &apo ...

The Webstorm AngularJS extension appears to be malfunctioning, as it is not able to recognize the keyword 'angular'

As a beginner in Angularjs and web development, I have been using Webstorm to develop my projects. I have already installed the Angularjs plugin, which seems to be working fine in my HTML files. However, I am facing an issue with my .js file. In this file, ...

Disabling keypress function in onKeyPress, yet onChange event still activates

In my ReactJS component, I have implemented a function that is triggered by the onKeyPress event: onKeyPress(e) { if (!isNumeric(e.key) && e.key !== '.') { return false; } } Although this function successfully prevents non-numer ...

Prevent index.html from being included in express.static when delivering React application using Express

Currently, I am using Express to serve a create-react-app's build. To append some script tags to the index.html before serving it, I am manipulating the file. However, I do not want my express.static middleware to handle requests for / or /index.html. ...

Error: The method specified in $validator.methods[method] does not exist

Having trouble solving a problem, despite looking at examples and reading posts about the method. The error I'm encountering is: TypeError: $.validator.methods[method] is undefined Below that, it shows: result = $.validator.methods[method].call( t ...