Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda