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

394
Visualizações
Uncaught Error: Too many re-renders. React limits the number of renders to prevent an infinite loop. error
import React from 'react'
import axios from "axios"
import { useEffect } from "react"
import { useState } from "react"

export function Profile (){
    const pathname = window.location.pathname
    const[data,setData] = useState([])
    const [loaded,hasloaded] = useState(false)

  let username = pathname.split("/")[1]

useEffect(()=>{
    axios.post('http://localhost:5000/profile/getProfile', {
        "username":username
       })
       .then((res)=> setData(res.data))
})

  return (
    <div className='Wrapper'>
   
    <img/>

{loaded ? <h2>{data[0].username}</h2>:<h2>Loading</h2>}
  
    <img  />

    </div>
  )
}

axios it taking like 10 seconds to get the response is this normal? when i request on postman it takes like 1 second. also how can i render when i have recieved the data without causing to many rerenders?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When the dependency array for useEffect is undefined (instead of an empty array) then the effect runs on every render. And within your useEffect you are updating state, which will trigger a re-render. This means every render triggers a re-render.

It looks like you only want the effect to run once, when the component first loads. For that, pass an empty dependency array to useEffect:

useEffect(()=>{
  axios.post('http://localhost:5000/profile/getProfile', {
    "username":username
  })
  .then((res)=> setData(res.data))
}, []); // <--- here
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