Struggling to achieve desired output from function in NextJS

I'm a bit confused by the code below.

The itmLoop function seems to work fine when placed directly in the return section, but nothing is output when it's called as shown below?

I'll eventually need to make it recursive, so I have to keep it as an external function.

Could someone help me figure out what I'm doing wrong?

Thanks a lot!

const Output = () => {

  const items = [
   {title:"lvl1-1",
    children:[
      {title:"lvl2-1"},
      {title:"lvl2-2"}
    ]},
   {title:"lvl1-2"},
   {title:"lvl1-3"}
  ];

  function itmLoop(arr=[]){
    arr.map((e)=>{
      return (<span>{e.title}</span>)
    })
  }

  return ( { itmLoop(itms) } )

}

export default Output

Answer №1

Appreciation to @Yaakov for bringing my error to light.

I overlooked the return statement prior to the map function.

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

Error: Headers cannot be set after they have already been sent, resulting in an Unhandled Promise Rejection with rejection id 2

I'm a beginner with Node.js and I've been using express.js. In a section of my code, I'm trying to retrieve data from a form via AJAX and store it in a variable called url. I have access to request.body, but I'm encountering an issue wh ...

Try out the Jquery Chosen plugin, which allows you to select multiple instances of the same

I am currently using the chosen plugin to create multiple select input fields. You can view an example of this in action by following this link: By default, the plugin disables an option if it has already been selected. For instance, in the provided examp ...

Automatically updating the results section while executing SQL queries in PHP

Here is a JavaScript/Ajax code snippet: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready (function () { var updater = se ...

Limit the selected values to calculate a partial sum

Imagine two distinct classes called professor and student: professor.ts export class Professor { id: number name: string } student.ts import { Professor } from "./professor" export class Student { ...

"PHP script for submitting a form with a post button

Can anyone help me figure out why the submit function isn't working? I've been trying to solve the problem with no luck so far. Any ideas on what might be causing this issue? <?php if(isset($_POST['submit'])){ echo ("Submit fun ...

Ajax received a response from http 409 and is now parsing it

Hey there! I've been working on parsing out the message object using Ajax, and I'm having a bit of trouble getting a reference to messages.msg. It's strange because it displays perfectly fine in Postman, but for some reason, I can't see ...

Efficiently submitting multiple forms in a single click

On my photo portfolio admin page, I have created a feature to caption, keyword, and credit each photo. Previously, I had multiple forms listed dynamically with submit buttons for each form. With over 20 photos/forms on the page, this process became tedious ...

CombineReducers takes all the reducer content and unpacks it into a single reducer

As I work on developing a small application, I am contemplating the best strategy for organizing reducers within it. My objective is to retrieve JSON data from the application state and structure it as shown below: { "fruits": [ {"appl ...

The Google Charts chartRangeFilter displays incorrectly upon reducing the height to a specific, seemingly random level

I am relatively new to web coding and currently working on a dashboard project for my client. I am using Google Charts to display the water level data that I collect. My issue is with the chartRangeFilter control - it works fine when the height is large en ...

Implementing JWT Authentication in Next.js

I have made the decision to transition a project from React to Next.js and have some doubts regarding whether the authentication process remains appropriate. Essentially, the user inputs their username and password which is then verified against database c ...

How can you match something once in NodeJS?

I am experiencing an issue with my HTTP NodeJS server - every time I visit the URL, it outputs the result twice. const https = require('http'); const fs = require('fs'); const url = require('url'); https.createServer((req, r ...

The following version of i18next does not retrieve data from an endpoint

I am facing an issue in my Next.js project where I am trying to access a language json file from a CMS using next-i18next, but my current configuration is not functioning as expected. Below is my 'next-i18next.config.js' code: const I18NextHttpB ...

Require assistance in accurately assigning a date to a Date[] in Typescript Array without altering current elements

In my current code, I have a loop that verifies if a date is a holiday and then adds it to an array. The issue I'm facing is that whenever I assign a new element to the array, all previous data in the list gets updated to the latest element. Here&apos ...

Issue: Typescript/React module does not have any exported components

I'm currently facing an issue with exporting prop types from one view component to another container component and using them as state type definitions: // ./Component.tsx export type Props { someProp: string; } export const Component = (props: ...

Issue with Browsersync functionality in Docker

My Node.js app is facing an issue with Gulp, Browsersync, and Docker. When I run gulp watch locally, everything functions correctly. However, when I utilize docker-compose up, I encounter an error Cannot GET / The Browsersync UI on port 3001 is operat ...

Tips for ensuring session token verification remains intact upon reloading

I am currently in the process of developing a website using the Next.js framework and I am seeking advice on how to prevent the reload effect that occurs when transitioning from the login page back to the main page for just a fraction of a second. Below i ...

Utilizing titanium to develop a functionality that listens for button presses on any area of the screen

I am trying to simplify the action listener for 9 buttons on a screen. Currently, I have individual event handlers set up for each button, which seems inefficient. Is there a way to create an array of buttons and manipulate them collectively? For example ...

Express receiving undefined data in Ajax POST request

I'm currently facing an issue with sending data to be parsed. The client-side script I have is as follows: function addURL(link) { console.log("Adding url..."); $.ajax({ type: "POST", url: location.protocol + "/ ...

Tips for creating $http calls in AngularJS

Having some issues with my code, as I'm unsure of the correct placement for making an $http request to a local server. api.js var express = require('express'); var router = express.Router(); var mongoose = require('mongoose'); va ...

What is the method to run a script within a particular div?

Here is an example of the DOM structure: <div> <button>Click me</button> <img src=#> </div> <div> <button>Click me</button> <img src=#> </div> <div> <button>Clic ...