Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

283
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda