Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!