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

116
Views
Load same instance of a component in another component onClick in reactJs

I have two components smallViewComponent.jsx and fullViewComponent.jsx. In smallViewComponent.jsx, there are 3 instances of <AbcComp>.

So, the requirement is how to get these <AbcComp> instance on button click loadInstance() and render the different instances of <AbcComp> in fullViewComponent.jsx.

smallViewComponent.jsx

import AbcComp from './..'

 this.state = {
   cmpInstance = ['component1','component2','component3'];
 }
  
    
    render (){
       return (
               <div>
                   this.state.cmpInstance.map((e, index) => 
                        return (
                              //'component1','component2','component3' instance of AbcComp 
                            <AbcComp key={e} btnProps={e}/>  
                                                             
                         )       
              </div>
       )
    }

AbcComp.jsx

render(){
       // based on btnProps some diffrent color is added here
      return (<div><Button className={this.props.btnProps}/></div>) 
 }

fullViewComponent.jsx

loadInstance =() => {
  let cmpInstance = ['component1','component2','component3'];
   return cmpInstance[(Math.random() * cmpInstance .length) | 0]
}

render (){ 
       <button onClick={(e) => this.loadInstance()}></button>
     // dynamically load 'component1','component2','component3' instance of AbcComp below.
        <AbcComp /> 
}
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!