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

182
Views
Firebase v.9 deleteDoc( ) doesn't do anything nor catches any error

I'm new to React and Firebase, and I got a problem where the delete document function doesn't get called and no errors were caught. The function deleteItemHandler( ) does run, but the deleteDoc( ) doesn't. I have changed rules and make sure the imports are correct, yet it still won't work.

deleteItemHandler( ), App.jsx

  //? Delete item function
  const deleteItemHandler = async (id) => {
    try {
      await deleteDoc(doc(db, "items", id));
    }
    catch (error) {
      console.log(error);
    }
  }

Delete Button, YourCard.jsx

        <button
          className="btn btn-danger ms-2"
          onClick={() => {
            // console.log(props.name)
            props.deleteItemHandler(props.id)
          }}
        >
          Delete
        </button>

Note update: props passing App.jsx to UserIdentity.jsx

<UserIdentity
        className="userId"
        currentUser={username}
        loginHandler={loginHandler}
        logoutHandler={logoutHandler}
        addListingHandler={addListingHandler}
        //? for YourCard
        itemsFromDB={itemsFromDB}
        deleteItemHandler={deleteItemHandler}
      />

UserIdentity.jsx to YourCard.jsx

{yourItems.map((item) => {
                        return (
                          <YourCard
                            // className="YourCard"
                            name={item.name}
                            id={item.id}
                            key={item.id}
                            deleteItemHandler={props.deleteItemHandler}
                          />
                        );
                      })}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

im thinking you're not handling props correctly

 const App = () => {
    const deleteItemHandler = async (id) => {
        await deleteDoc(doc(db, "cities", id));
    }

 return (
     <YourCard deleteItemHandler={deleteItemHandler} id={someId}}
 ) 

child

  export const YourCard = ({deleteItemHandler, id}) => {
  
  return (
    <button
      className="btn btn-danger ms-2"
      onClick={() => deleteItemHandler(id)}
    >
      Delete
    </button>
  )
about 4 years ago · Juan Pablo Isaza Report

0

Finally figured out that the problem lies on addDoc(), which adds new document with yc2 type while deleteDoc() searches documents with mc2 type. Changed the add method to setDoc() fixes it.

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!