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

242
Visualizações
How to pass id using Link in React JS

i have create a simple website.I have to create two pages first page is to show various catergories. Second page is to details. for example images, description also. i have click link to pass data from second page but still now i have error can not pass data. Error:

React Hook useEffect has a missing dependency: 'fetchiditem'. Either include it or remove the dependency array react-hooks/exhaustive-deps

How to solve my error please give me solution.

App.js

<Routes>
  <Route path='/shop' exact element={<Shop />}></Route>
  <Route path='/shop/:id' element={<Shopdetails />}></Route>
</Routes>

Shop.js

 function Shop() {
  useEffect(() => {
    fetchitems();
  }, []);

  const [items, setItems] = useState([]);
  const fetchitems = async () => {
    const data = await fetch("https://fortnite-api.theapinetwork.com/upcoming/get"
);
    const itemsdata = await data.json();
   // console.log(itemsdata.data);
    setItems(itemsdata.data);
  };

  return (
    <div>
      {items.map(item => (
        <h1 key={item.itemId}>
        <Link to={`/shop/${item.itemId}`}>{item.item.name}</Link>
        </h1>
      ))}
    </div>
  );

}

export default Shop;

Shopdetails.js

    function Shopdetails({match}) {
  useEffect(() => {
    fetchiditem();
  }, []);
  const [itemid, setitems] = useState([]);
 
  console.log(match);

  const fetchiditem = async () => {
    const data = await fetch (`https://fortnite-api.theapinetwork.com/item/get?id=${match.params.id}`
    );
    const itemdata = await data.json();
    setitems(itemdata.data.item);
  }
  return (
    <div>
      <img src={itemid.images.icon} alt="" />
    </div>
  );
}

export default Shopdetails;
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You have to provide the fetchiditem in the array:

useEffect(() => {
  fetchiditem();
}, [fetchiditem]);
about 4 years ago · Juan Pablo Isaza Relatório

0

Define the function inside the useEffect

useEffect(() => {
    const fetchiditem = async () => {
        const data = await fetch(
            `https://fortnite-api.theapinetwork.com/item/get?id=${match.params.id}`
        );
        const itemdata = await data.json();
        setitems(itemdata.data.item);
    };

    fetchiditem();
}, [match.params.id]);
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