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

301
Vistas
Why Props isn't working in nextjs-typescript?

Why props isn't working in my project. I can't figure out! Here is the three file. I am just learning typescript. But the code isn't error but still not working!

This is index.tsx file

index.tsx

    const Home: NextPage = () => {
  
  return (
    <div className={styles.container}>
      <Header name={"ali Ahad"} />
      <PersonList Person={Person} />
    </div>
  )
}

export default Home

This is PersonList.tsx file

PersonList.tsx

type personType={
  Person:{
    name:string,
    age:number,
    address:string

  }[];
    
};

const PersonList=(props: personType)=> {
  return (
    <>{props.Person.map((man)=>{
        <div>
        <h1>{man.name}</h1>
        <h2>{man.age}</h2>
        <h3>{man.address}</h3>
        </div>
        
    })}</>
  )
}

export default PersonList

This is Data.tsx file

Data.tsx

const Person=[
    {
        name:"John",
        age:30,
        address:"New York"
    },
    {
        name:"Ali",
        age:25,
        address:"New York"
    },
    {
        name:"Ahmad",
        age:20,
        address:"New York"
    },
]

export default Person;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're not seeing any of the persons being displayed/rendered because you're missing an explicit return statement in your map()'s arrow function.

// returning from a block body (braces) requires an explicit `return`
return (
  <>
    {props.Person.map((man) => {
      /* missing `return` */
      <div>
        <h1>{man.name}</h1>
        <h2>{man.age}</h2>
        <h3>{man.address}</h3>
      </div>;
    })}
  </>
);

You would need to do something like this...

// with an explicit `return` this will work, albeit verbose
return (
  <>
    {props.Person.map((man) => {
      /* `return` added */
      return (
        <div key={man.name}>
          <h1>{man.name}</h1>
          <h2>{man.age}</h2>
          <h3>{man.address}</h3>
        </div>
      );
    })}
  </>
);

...but this would be more concise:

// removing the braces (replaced with parentheses) will make things concise
// and the `return` will be implied
return (
  <>
    {props.Person.map((man) => (
      <div key={man.name}>
        <h1>{man.name}</h1>
        <h2>{man.age}</h2>
        <h3>{man.address}</h3>
      </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