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

428
Visualizações
React useParams undefined

I am doing a personal React.js project. I am having issues with useParams. One of the issues that I am facing is that I cannot find a common id for the useParams. I am not able to show on screen the items that I pass as props in ItemDetails. This is the ItemContainer.:

import { useEffect, useState } from "react";

import ItemDetails from "../Itemdetails";
import { useParams } from "react-router-dom";

const showRace = async (raceId) => {
  const res = await fetch("https://www.betright.com.au/api/racing/todaysracing");
  const json = await res.json().result;
  const race = Object.keys(json).find((findKey) => findKey === String(raceId));

  if (!race) {
    throw new Error("No match found.");
  }
  console.log('race in showRace', race)

  return race;
}

const ItemContainer = () => {
  const [venue, setVenue] = useState({});
  const { raceId } = useParams();

  useEffect(() => {
    showRace(raceId)
      .then((races) => {
        setVenue(races)
      })
      .catch(error => {
        console.error('error useEffect itemContainer', error)
        setVenue({});
      })
  }, [raceId]);
  console.log("venue container", venue);

  return <ItemDetails key={raceId} venue={venue} />;
};

export default ItemContainer;

This is the ItemDetails:

const ItemDetails = ({ venue }) => {
  console.log("venue itemDetails", venue);
  return (
    <>
      {Object.entries(venue).map(([key, value]) => (
        <div key={key}>
          <h1>{key}</h1>
          {value.slice(0, 5).map((i, races) => (
            <div key={i}>
              <p>{races.Venue}</p>
            </div>
          ))}
        </div>
      ))}
    </>
  );
};

export default ItemDetails;

This is a link to a codesandbox with the whole code.

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