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

263
Visualizações
fetch request is not working while using react js and express js, Unhandled Rejection (TypeError): Failed to fetch

I am using react js and express js program. I have created express server, however my react js app is not working with my express js. I am showing you codes of react js below

import React, { useEffect, useState } from 'react';

const Get = () => {
  
  const [users, setUsers] = useState([])

  useEffect(() => {
    fetch("http://localhost:3000/posts")
        .then((response) => response.json())
        .then((users) => {
            setUsers(users);
        })
  }, []);

  return (
    <>
      {users.map((post) => {
        return (
          <div>
            <p>{post.date}</p>
          </div>
        )
      })}
    </>
  )
}

export default Get

It says

Unhandled Rejection (TypeError): Failed to fetch

and I think that it is connected with my fetch request.

This is the information in my server:

[
  {"_id":"617fa514d55c0cced18b1f6b","title":"New Title","description":"Hello World","date":"2021-11-01T08:26:52.000Z","__v":0},
  {"_id":"617fa52bd55c0cced18b1f6d","title":"New Title","description":"Hello World","date":"2021-11-01T08:26:52.000Z","__v":0},
  {"_id":"617fa52cd55c0cced18b1f6f","title":"New Title","description":"Hello World","date":"2021-11-01T08:26:52.000Z","__v":0}
]
about 4 years ago · Juan Pablo Isaza
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