Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
how to make Individual toggle effects on buttons made with array map

I'm using react with firebase Data stored in the firebase is imported into useEffect, then setlist state is added, and div is generated as a map. What should I do when I want to give an individual toggle event for each button made with map?

When the toggle event becomes true, if edit is false, I want to output the add component.

my code

  let [list, SetList] = useState([]);
  let [toggle,setToggle] = useState(false);

  useEffect(() => {
   db.collection("title").onSnapshot((snapshot) => {
   let titleArray = snapshot.docs.map((doc) => ({
    ...doc.data(),
  }));
  SetList(titleArray);
}); }, []);

list.map(function(value,index){
 <button type="button" onclick={(e)=>{
  props.dispatch({type:"open"}}>click</button>

  toggle === true 
  ? <Edit/> //component 
  : <add/>  //component 
  })

When I press the first button, I want to change only the first button from false to true and keep the rest of the buttons false.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda