This is probably an easy fix however I'm unable to see the solution. My project that I've been taking way too much time on is finally starting to close up, however I'm towards the very end and I'm having problems with the API I'm working with.
I'm expecting that whenever I use my match in HeroDetail, I will be able to use that ID to locate the hero's who data I want to display whenever you click on it. My other components work exactly how I believe they should. They route me to my HeroDetail page with an ID that is specific to a hero I click on.
The problem I'm having is, with this API, I do not know how to use that ID to pull the heroStats for that specific ID out.
I thought I might be able to add a little params at the end of the URL like ?_id=${} but that was unsuccessful. The API URL is https://docs.opendota.com/#section/Introduction if you want to read a little on it as well. I haven't been able to find anything that can help me.
import React, {useState, useEffect} from "react";
import "./App.css";
function HeroDetail({match}) {
useEffect(() => {
fetchHero();
console.log(match)
},[]);
const [item, setItem] = useState([]);
const fetchHero = async () => {
const fetchHero = await fetch(`https://api.opendota.com/api/heroStats}`);
const item = await fetchHero.json();
setItem(item);
console.log(item)
};
return(
<div>
<h1>{item.id} </h1>
</div>
);
}
export default HeroDetail;
const hero = item.find(h => h.id === /* the id of the hero you want */)match.params.idin the data you get from thefetch()?match.params.idis indeed a Number and not a string?