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

93
Vistas
Why is my react on click event not firing a function call?

I'm developing a chatting app and want to add a button to delete messages. I'm using react and firebase and I want a button to delete documents from the web app with a button but I've no clue how to.

I tried:

  const { text, uid } = props.message;

  const messageClass = uid === auth.currentUser.uid ? "sent" : "received";

  return (
    <>
      <div className={`message ${messageClass}`}>
        <p>{text}</p>
        <button onClick={firestore.collection("messages").doc().delete()}>
          Delete
        </button>
      </div>
    </>
  );
}

React returns: Error: Expected onClick listener to be a function, instead got a value of object type. at me and I'm clueless as to what to do.

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

0

React onClick expects a function you should write:

<button onClick={() => firestore.collection("messages").doc().delete()}>

The reason your code fails is because you are evaluating the delete instead of passing it for react to call when you click the button.

<button onClick={firestore.collection("messages").doc().delete}>

Should also work, notice the lack of parentheses on delete.

You can read more about react events here

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