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

297
Views
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 answers
Answer question

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 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!