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

140
Vistas
How can I assign modal form component opening function to any another button component

I have 2 components: ModalForm and BookCard. The ModalForm is supposed to be put inside of the BookCard. When you put the ModalForm - it creates new button and functionates as it has to. But what if instead of creating new button I want to assign ModalForm's functionality to already existing button?

BookCard.js

const BookCard = ({id, name, cover, description, price, count, loadResponse}) => {
    return (
        <Card>
            //some code
            <ModalForm /*some props*/ />
            <button className="edit-button"> // <- the button, I want to be assigned to be opening modal
                <box-icon name='edit-alt'/>
            </button>
        </Card>
    );
}

ModalForm.js

const ModalForm = ({/*some props*/}) => {
    //some code
    return (
        <div>
            <Button onClick={handleClickOpen} /> // <- the button that is being shown instead of the wanted one
            //some code    
        </div>   
    );
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Its looks like you need to handle the logic in the most up component in your case BookCard. So ModalForm has some props like isOpen in BookCard you need state like isModalOpened and then add callback onClick that change state (isModalOpened) and then react pass that prop(isOpen) to your ModalForm.

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