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

95
Visualizações
Next js Button reload site and new fetch

I want to create a refresh Button. Reloading the page already works, but unfortunately the data is not re-fetched. Does anyone of you have an idea?

The code from the update button is:

    const { reload, query } = useRouter();

                    <Button
                        onClick={() => {
                            reload();
                        }}
                    >
                        Refresh
                    </Button>

The code from the fetch is:

const { data } = await axios.get(`http://localhost:5000//${nr}`);
        const extractedData = data.data;
        setData(extractedData);

        if (extractedData) {
            const unixTimestamp = data.data.unixtime;
            const millisecons = unixTimestamp * 1000;
            const dateObj = new Date(millisecons);
            const humanDateformat = dateObj.toLocaleString();
            setunixTime(humanDateformat);
        }
    }, []);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It appears that you might want to recall the query and not refresh the page. You can assign the fetch call to a function and call the function on click. This would look something like the following:

import { useEffect, useState } from 'react';

const Page = () => {
  const nr = '/api/route/path';
  const [data, setData] = useState([]);

  const fetchData = async () => {
    try {
      const { data } = await axios.get(`http://localhost:5000//${nr}`);
      setData(data.data);
      console.log(data.data);
    } catch(e) {
     console.log(e);
    }
  }
  
  useEffect(() => { fetchData() }, []); //fetch data on page load
 
  return <Button disabled={loading} onClick={fetchData}>Refresh</Button>;
}
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