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

276
Vistas
Why am I getting a network error on page refresh? (get request)

I'm making a get request to an API in a useEffect(). When I navigate to the page from the homepage it loads fine, but as soon as i refresh the page http://localhost:3000/coins/coin I get a Unhandled Runtime Error: Error: Network Error.

export async function getServerSideProps({ query }) {
  const id = query;
  return {
    props: { data: id },
  };
}

function index({ data }) {
  const coinURL = data.id; // bitcoin
  const apiEndpoint = `https://api.coingecko.com/api/v3/coins/${coinURL}`;
  const [currentUser, setCurrentUser] = useState();
  const [coinData, setCoinData] = useState([]);

  useEffect(() => {
    const getData = async () => {
      const res = await axios.get(apiEndpoint);
      const { data } = res;
      setCoinData(data);
    };
    const getCurrentUser = async () => {
      const res = await axios.get(
        `http://localhost:5000/api/users/${session?.id}`
      );
      const { data } = res;
      setCurrentUser(data);
    };
    getData();
    getCurrentUser();

  }, [coinData, currentUser]);
}

Why does this happen?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'm recommending to do something like this:

const getData = async () => {
    try {
        const res = await axios.get(apiEndpoint);
        const { data } = res;
        setCoinData(data);
    } catch(err) {
        console.log(err)
    }
};

const getCurrentUser = async () => {
    try {
        const res = await axios.get(
            `http://localhost:5000/api/users/${session?.id}`
        );
        const { data } = res;
        setCurrentUser(data);
    } catch(err) {
        console.log(err)
    }
};

useEffect(() => {
    getData();
    getCurrentUser();
  }, [coinData, currentUser]);

if you do so, you will be able to view the exact error and fix 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