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

306
Vistas
i have two components{addressone},{addresstwo} and want to add and delete {addresstwo} on button click inside {addressone} component

address two component

 `<AddressTwo/>`

i had applied toggle logic but i am trying to add and delete component

  <Button
    onClick={()=>setIsToggled(!isToggled)}>+</Button>

    {isToggled && <AddressTwo/>}

add when this is clicked

   `<Button >+</Button>`

remove component when this button is clicked

  ` <Button>-</Button>`
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Change your way to do,

think that the address is one component that receives 1 object

{ id: Number, street: String, number: String, postCode: String }

and the number of addresses is an array of object

[ {...}, {...}]

in react it's maybe easier to manage this way

const [addresses, setAdresses] = useState([])

const addOne = () => setAddresses([...addresses, { id: null, street: "", number: "", postCode: "" }]

{...}

return(
  <>
    <h1>hello from profile</h1>
    <button onclick={()=>addOne()}/>+</button>
    {addresses.map((address, i)=>(
       <AddressComponent address={address} />
    )}
  </>
)

the code is not perfect but you got the IDEA

then from there, you can play with the array as you want... (pop, push, limit, find, etc...)

courage...

about 4 years ago · Juan Pablo Isaza Denunciar
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