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

108
Visualizações
Why doesn't my image show on my react app page?

So i've been trying to show an image on my page with an API, but everytime I go to the page I see the image for a few seconds and after that the page refreshes and it shows an error:

Uncaught TypeError: location is undefined

I think the problem could be about the way I used my image, but i am not sure. If I console log the image it just shows the correct image name. This is the code I used:

import { Row, Col } from "react-grid-system";
import { Separator } from "@fluentui/react";
import * as React from "react";
import { useEffect, useState } from "react";

function Recipe(props) {

  const axios = require('axios');
  const api = axios.create({
    baseURL: 'http://localhost:5000/',
    timeout: 10000
  })
  const [recipe, setRecipe] = useState({});
  const [image, setImage] = useState({});

  useEffect(() => {
    getRecipe()

  }, [])

  function getRecipe() {
    api.get('/recipe/' + props.id).then(res => {
      setRecipe(res.data);
      setImage("https://localhost:5001/Uploads/" + res.data.image)
    });
  }

  return (
    <div>
      <div>
        <Row>
          <Col sm={6} md={6} lg={6}>
            <img style={{ width: "700px", marginTop: "20px" }} src={image} alt={"error"} />
          </Col>

          <Col style={{ marginTop: "20px" }} sm={6} md={6} lg={6}>
            <Separator className={"Separator"} />
            <h1>Naam: <div style={{ fontSize: "20px" }}>{recipe.name}</div></h1>
            <h1>Ingredienten: <div style={{ fontSize: "20px" }}> {recipe.ingredients}</div>
            </h1>
            <h1>Macro's:
              <div style={{ fontSize: "20px" }}>
                <ul>
                  <li>Kcal: {recipe.carbs}</li>
                </ul>
              </div>
            </h1>
            <h1>Voorbereiding: <div style={{ fontSize: "12px" }}>

              {recipe.preparation} </div></h1>

          </Col>

        </Row>

      </div>

    </div>
  )
}
export default Recipe


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