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

284
Vistas
How do I fetch data when data is added, deleted or edited in next js?

Can you please tell me how to fetch data when data is added, deleted, or edited in next js? I have used useEffect, used a state to run useEffect but that is not working properly in my case, only when I add data, the useEffect function is triggered. But in edit or delete, it's not. I have used multiple compnents. So, how can I achieve this? (without state triggering the useEffect function). Thanks in advance!

const [added, setAdded] = React.useState(0);

React.useEffect(() => {
  async function getTodos() {
    const todosCol = collection(db, "todos");
    const todoSnapshot = await getDocs(todosCol);
    const todoList = todoSnapshot.docs.map((doc) => doc.data());

    setTodos(todoList);
  }
  getTodos();
  console.log("Use effect ran!!!");
}, [added]);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I am convinced. You have to use Redux or any other state management tools for achieving this. :)

about 4 years ago · Juan Pablo Isaza Denunciar

0

I think your implementation needs refactoring.

The problem is mutable and immutable variables. But if you want this code working, just store added as a property inside state so that React can track the changes.

something like this:

const [state, setState] = useState({added: 0});
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