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

256
Visualizações
Unable to fetch html content in vercel server using React

I am working with Reactjs and using nextjs framework,Html content(description_front) is showing data fine in localhost Here is api response (console)

Object
id: "55"
description_front: "<h3><strong>The crypto revolution and its effects</strong></h3>"

but whenever I am trying to display ,"html" content in server(vercel) via api, i am getting following data in my console,But whenever i am trying to display "description_front" in web page i am getting following error

Cannot read properties of undefined (reading 'description_front')

Here is my code, where i am wrong ?

import Axios from "axios";
import  {useRouter}  from "next/router";
const Post = ({ post }) => {
  const router = useRouter();
  const htmlString = post.description_front;
  return (
    <>
    <div className="product-des" dangerouslySetInnerHTML={{ __html: htmlString }} />
    <>
    );
  };
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When fetching data from localhost, the fetching is probably very quick, means that the data will be fetched even before the page render will be completed, and the original code will work as supposed.

But when fetching from a remote server, it takes more time, so the rendering process will be done before the data is fetched, and post.description_front will be null, what's causing this error.

The solution will be to check if the value is null before rendering, so a one liner will be: const htmlString = post?.description_front instead of const htmlString = post.description_front

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