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

150
Views
Map State in reactjs

I'm trying to map also functions from object

const KindOfShoots = [
{ id: 1, name: "Shoot in Studio", 
link: "/Photoshoot",icon:"fa fa-calendar", 
onClickAction: "setToggle1"  },
{ id: 2, name: "Shoot at other Location", 
link: "/Photoshoot" ,icon:"fa fa-calendar", 
onClickAction: "setToggle2" },];

snippets below:

{
            KindOfShoots.map((type)=>(
              
                <KindOfShootLayout > 
                   <div className="KindOfShootLayout" onClick={() => 
                    {type.onClickAction}((t) => !t)
                    }>
                      {type.name}
                      <i className={type.icon}></i> 
                   </div>
                    
                   
                </KindOfShootLayout>
            ))
        }

I need to change the states toggle1 & toggle2 and also store the states and pass them to another component, I'm a little blocked

 const [toggle1, setToggle1] = useState(true);
 const [toggle2, setToggle2] = useState(true);

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

0

const KindOfShoots = [
{ id: 1, name: "Shoot in Studio", 
link: "/Photoshoot",icon:"fa fa-calendar", 
onClickAction: setToggle1  },
{ id: 2, name: "Shoot at other Location", 
link: "/Photoshoot" ,icon:"fa fa-calendar", 
onClickAction: setToggle2 },];

{
  KindOfShoots.map((type)=>(
    <KindOfShootLayout > 
      <div className="KindOfShootLayout" onClick={() => type.onClickAction(!toogle)}>
           {type.name}
           <i className={type.icon}></i> 
       </div>
    </KindOfShootLayout>
    ))
  }
about 4 years ago · Juan Pablo Isaza Report

0

Ok, I think I found an answer; I used the property onToggle

const KindOfShoots = [
{
  id: 1,
  name: "Shoot in Studio",
  link: "/Photoshoot",
  icon: "fa fa-calendar",
  onToggle: setToggle1,
  toggle: toggle1,
  
},
{
  id: 2,
  name: "Shoot at other Location",
  onToggle: setToggle2,
  toggle: toggle2,
  link: "/Photoshoot",
  icon: "fa fa-calendar",
  
},

];

And it returns

{KindOfShoots.map((type) => (
    <KindOfShootLayout>
      <div style={{display: toggleActual}}
        className="KindOfShootLayout"
        onClick={() => type.onToggle(!type.toggle)}
      >
        {type.name}
        <i className={type.icon}></i>
      </div>
    </KindOfShootLayout>
  ))}
  <div style={{ display: toggle1 ? "none" : "block" }}>
    <ThirdGrandchild />
  </div>
  <div style={{ display: toggle2 ? "none" : "block" }}>
    <SecondGrandchild />
  </div>
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!