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

267
Visualizações
Whenever i try to use .map for fetching the data, i got error

whenever i try to fetch the data with .map function is show me the error

user.map is not a function

I use the below code for fetching the data

 user.map((user,index) => <>
         <h1> {user.name} </h1>
         <h1> {user.address} </h1>
     </>)

And use the below code for getting the data from backend,

  const [user, setUser] = useState([
{
    name:'',
    phone:'',
    bgroup:'',
    pincode:'',
    address:''
}
  ]);

useEffect(() => {
    fetch("/Donate").then(res=>{
        if(res.ok){
            return res.json();
        }
    }).then(jasonRes=>setUser(jasonRes));
},[])
  

With this , i get data in console , when i use the below code

 console.log(user)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const [user, setUser] = useState([]);
            
useEffect(() => {
  fetch("/Donate").then(res=>{
        if(res.ok){
            return res.json();
             }
        }).then(jasonRes=>setUser(jasonRes && jasonRes.Donate));
    },[])
        
     return (
        <>
          {user.map((el, i)=> {
            <div key={i}>
               <h1> {el.name} </h1>
                <h1> {el.address} </h1>
              </div>
           })}
       </>
  )
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