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

187
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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