Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

75
Vistas
how do i pass props a react bootstrap button onClick function to anther component
const [modalShow, setModalShow] = React.useState(false);

return (
    <> 
        <Button variant="primary" onClick={() => setModalShow(true)}> Launch vertically centered modal
        <MyVerticallyCenteredModal
            show={modalShow}
            onHide={() => setModalShow(false)}
        />
    </>
)
7 months ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

If I understand correctly, you can pass a method to child component with props like this :

const TopComponent=()=>{
const [modalShow, setModalShow] = React.useState(false);
const MethodA=()=>{
   setModalShow(false)
}
return (
    <div>
      <Button onClick={MethodA}/>
      <MyVerticallyCenteredModal onClick={MethodA} />
    </div>
  );
};
const MyVerticallyCenteredModal = ({onClick}) => {
  return (
    <div>
      <Button onClick={onClick}/>
    </div>
  );
};
7 months ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos