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

109
Views
Tyepscript Array.map returns array of JSX.Element instead of custom component type
var items = values.map((x, index) =>
   <CustomComponent key={index} />);

This returns JSX.Element[]. Why doesn't it return typeof CustomComponent[]?

With the former, then I can't use items.sort without difficult errors.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It's correct. It returns JSX.Element[] because you are rendering CustomComponent immediately. If you want to work with element sort/filter or something else you need filter data before render.

values
   .filter(x => //filter your values)
   .map((x, index) => // render your components
<CustomComponent key={index} />);
about 4 years ago · Juan Pablo Isaza Report

0

yes,

like Egor said, your map result is CustomComponent resuls array.

if you want to your component instance array try some thing like this

export  type CustomComponentType = () => JSX.Element;

export  const CustomComponent : CustomComponentType = ()=> {
    return <div>my componen result</div>
} 

export const test : CustomComponentType[] = ()=> {
    const array = [1,2,3,4,5,6,7,8,9];
    const componentArray =  array.map(c => CustomComponent);
    return componentArray;
}
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!