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

87
Views
Render React Components with .map()

I've read about 10 other posts about this but they're all outputting really simple objects, strings and reading from JSONs. I am opening a modal, taking user input from an and setting the state with onChange(). On submit, the modal closes and there should be a component (imported from the component that generates them) pushed into an array. I can see that the element indeed is pushed into the array, but it isn't conditionally rendered using buttonsArray.map() OR by setting that map.() function to a variable and using {someVar} in the render area.

This is the code as it stands now (just sharing the relevant bits):

const buttonsArray: JSX.Element[] = [];

let mappedArray = buttonsArray.map((button, i) => {
  console.log("TEST!");
  return <li key={button + "-" + i}>{button}</li>;
});

const submit = () => {
  buttonsArray.push(<SuperpowerBtn icons={icons[1]} iconText={userInput} />);
  handleCloseModal();
};

and in the render I have:

<ul style={{ margin: 0, padding: 0 }}>{mappedArray}</ul>

and before this I had tried putting the .map() function within {...} in the render instead. Is it in the type declaration of buttonsArray? Because when I console.log() the array I get a strange object print out in some kind of weird JSON format describing the HTML element of type 'i' which is the FontAwesome icon being rendered as part of the component. I've tried rendering it every which way (with and without UL/LI) I could think of off the top of my head, also to no avail...Where am I going wrong?

about 4 years ago · Juan Pablo Isaza
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!