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

135
Vistas
Data returned from server renders on the page when refreshed (but not when I change to its route)

PROBLEM: Data returned from the server only renders on the page when refreshed (and not when I change to its route)

So in other words, when I hit the route /repay, the data is returned from the server but it doesn't re-render on the page.

Here is my function that does the following:

  • fetches data from server
  • takes data and requests new data from second server
  • returns data in tokens variable
useEffect(() => {

    if (userAddress) {
      (async () => {

        // fetch data from server
        const res = await axios.get(
          `${config.api.invokeUrl}/users/${userAddress}`
        );

        // take data and send to another server 
        const tempTokenMetadata = []; 
        res?.data?.Items?.map(async (loan, index) => {
          const options = {
            address: loan?.tokenAddress,
            token_id: loan?.tokenId,
            chain: "kovan",
          };
          const tokenIdMetadata =
            await Moralis.Web3API.token.getTokenIdMetadata(options);
          tempTokenMetadata.push(tokenIdMetadata);
        });
        setTokens(tempTokenMetadata);
      })();
    }
    setLoading(false);
  }, [userAddress]);

I'm getting userAddress from my global state value:

const [{ userAddress }] = useStateValue();

Here is how I'm rendering the code on the page:

{tokens?.map((token, index) => {
            return (
              <Grid item xs={10} sm={4} md={4} key={index}>
                <NFT key={index} token={token} />
              </Grid>
            );
          })}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Have you tried removing the userAddress from useEffect second parameter? like this

useEffect(() => {

    if (userAddress) {
      (async () => {

        // fetch data from server
        const res = await axios.get(
          `${config.api.invokeUrl}/users/${userAddress}`
        );

        // take data and send to another server 
        const tempTokenMetadata = []; 
        res?.data?.Items?.map(async (loan, index) => {
          const options = {
            address: loan?.tokenAddress,
            token_id: loan?.tokenId,
            chain: "kovan",
          };
          const tokenIdMetadata =
            await Moralis.Web3API.token.getTokenIdMetadata(options);
          tempTokenMetadata.push(tokenIdMetadata);
        });
        setTokens(tempTokenMetadata);
      })();
    }
    setLoading(false);


    // ----Look here ⬇⬇⬇⬇----


  }, []);

this will make your useEffect execute only once when the component is rendered. and not when userAddress value changes.

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