Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda