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

138
Views
How do you render multiple views of a component in index.js via an array and click event?

Recently I have been creating an app to display various data from a database, currently I am attempting to create a button to allow for a comparison between two date ranges, my solution is to allow the user to click compare and then add an additional copy of the app component on the screen. In my app.js file I have done similar things using useStates in which I change data and the component rerenders but here it seems to do nothing when adding to the multiview array. Setting the array ahead does render the copy of the component however the button press does not, I assume that this is due to it not rerendering when the array is updated due to using ReactDom.render rather than returning a component as I've previously done in App.js and it's components.

Code for index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import MenuBar from './components/MenuBar'

var multiView = [];
var i = 0;
var handleDateCompare = (e) => {
  i++
  multiView.push(<App key={"app"+i} dateCompareClick = {handleDateCompare}/>)
  console.log(multiView);
}

ReactDOM.render(
  <React.StrictMode>
    <MenuBar />
    <App dateCompareClick = {handleDateCompare}/>
    {multiView}
  </React.StrictMode>,
  document.getElementById('root')
);
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!