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

164
Views
ReactJS issue when doing component recursion "Uncaught TypeError: nodes1 is undefined"

I have a problem when referencing the component itself to build a group of components from a list. How can I make such recursion in a component? From where I got "nodes1" call?

NotesGroup.js

import React from "react";
import Note from "./Note";

const NotesGroup = ({ notes }) => {
  return (
    <div>
      {notes.map(({ id, note, nodes }) => {
        return <Note key={id} id={id} note={note} nodes={nodes} />;
      })}
    </div>
  );
};

export default NotesGroup;

Note.js

import React from "react";

const Note = ({ id, note, nodes }) => {
  return (
    <div className="note">
      <span className="note__id">{id}</span>
      <span className="note__note">{note}</span>
      nodes ?{" "}
      {nodes.map(({ id, note, nodes }) => {
        return <Note key={id} id={id} note={note} nodes={nodes} />;
      })}
      : null
    </div>
  );
};

export default Note;

sample notes object (passed to NotesGroup component)

const notes = [
    {
      id: uuidv4(),
      note: "This is a note",
      nodes: [
        {
          id: uuidv4(),
          note: "This is a note 2",
          nodes: [
            {
              id: uuidv4(),
              note: "This is a note 3",
            },
          ],
        },
        {
          id: uuidv4(),
          note: "This is a note 4",
        },
      ],
    },
    {
      id: uuidv4(),
      note: "This is a note 5",
    }
  ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You map is set up wrong. You can only pass in two params e.g value (the key of the array) index (the number of the array being rendered)

So change the following

const NotesGroup = ({ notes }) => {
  return (
    <div>
      {notes.map(({ id, note, nodes }) => {
        return <Note key={id} id={id} note={note} nodes={nodes} />;
      })}
    </div>
  );
};

to this

const NotesGroup = ({ notes }) => {
  return (
    <div>
      {notes.map((value, index) => {
        return <Note key={index} id={value.id} note={value.note} nodes={value.nodes} />;
      })}
    </div>
  );
};

then in Note.js you are trying to map the component that is the component itself? Assuming thats a typo you do a similar thing

change

const Note = ({ id, note, nodes }) => {
  return (
    <div className="note">
      <span className="note__id">{id}</span>
      <span className="note__note">{note}</span>
      nodes ?{" "}
      {nodes.map(({ id, note, nodes }) => {
        return <Note key={id} id={id} note={note} nodes={nodes} />;
      })}
      : null
    </div>
  );
};

to this

const Note = ({ id, note, nodes }) => {
  return (
    <div className="note">
      <span className="note__id">{id}</span>
      <span className="note__note">{note}</span>
      nodes ?{" "}
      {nodes.map((value, index) => {
        return <Note key={index} id={value.id} note={value.note} />; //CHECK THIS
      })}
      : null
    </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!