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

250
Vistas
React JS - Prevent Parent onClick when clicked on child onClick

Here is the jsx

When i click the ROW myParentClick is triggered but when i click on any child which is myChildClick myChildClick2

Then it triggers both the parent and child.

The Parent is triggered first and then the child

{myData?.map((item, index) => {
    return(
        <Row onClick={() => myParentClick(index)}>
            <Col>
                // some html tags
            </Col>

            <Col>
                // some html tags
            </Col>

            <Col>
                // React Bootstrap DropDown
                <DropDown>
                    <DropDown.Toggle>
                        // code
                    </DropDown.Toggle>
                    <DropDown.Menu>
                        <DropDown.Item onClick={() => myChildClick(index)}>
                            <p>some TEXT</p>
                        </DropDown.Item>
                    </DropDown.Menu>
                </DropDown>
            </Col>

            <Col onClick={() => myChildClick2(index)} >
                <p>some TEXT</p>
            </Col>

            <Col onClick={() => myChildClick3(index)} >
                <p>some TEXT</p>
            </Col>
        </Row>
    )
})}

I have tried, on child click e.stopPropagation(); which is not working

onClick={
    (e) => {
        e.stopPropagation();
        myChildClick(index)
    }
}

How to Prevent Parent onClick when clicked on child onClick ?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

i took your code and tried to reproduce your issue. for some reason your stopPropagation doesnt work for you, but when i tried it, it works fine:

https://stackblitz.com/edit/react-ts-mk1dcr

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try

onClick={
    (e) => {
        if (e.defaultPrevented) return
        e.preventDefault()
        
        myChildClick(index)
    }
}
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