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

132
Views
I am new to react. I want to render a child component using a single state using an onClick event in react JS

on Click of button the state should be able to render component using statename.map.. Thankyou

<div className="container mt-5">
      <div className="row">
        <div className="card pt-3">
          <div className="col-lg-12">
            <h4>Promotional Rates</h4>
            <p>
              Create promotional rate(s)
            </p>
            <button className="btn btn-primary my-3" onClick={???}>
              Add New Promotional Rates
            </button>
    <<<<<<<render child component here using .map>>>>>>>>>
          </div>
        </div>
      </div>
    </div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

creat a state and u can use whatever method in the js code bellow

import React,{useState} from "react"

const ParentComponent = () =>{
  const [ShowChild,setShowChild]=useState(false)
  
  return(
  <div>
  
    //methode 1
    {ShowChild && ChildComponent}
    // end methode 1
    
    
    //methode 2
    {ShowChild? <ChildComponent /> : ''}
    //end methode 2
    
    
    
    <button onClick={()=>setShowChild(!ShowChild)}>show child Button </button>
  </div>
  )}
  
  
const ChildComponent = () => {
  return(
    <h1>I m a child</h1>
    )
    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

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!