Hi guys i'm trying to loop through this array that im getting from this array: "https://us-central1-nft-cloud-functions.cloudfunctions.net/hotCollections"
I have a function that gives me the nftId as params, I want to use those params to target the same id that the one of the object of the array has and I want to display the information that matches.
the Code:
const {nftId} = useParams();
const [posts, setPost] = useState([]);
console.log(nftId)
async function fetchPost(nftId) {
const {data} = await axios.get(`https://us-central1-nft-cloud-functions.cloudfunctions.net/hotCollections`)
setPost(data)
let lookup = {};
for (let i = 0; i < posts.length; i++) {
if (posts.nftId === nftId) {
lookup[posts[i].nftId] = posts[i]
console.log(lookup)
}
}
//data.filter(x => x.nftId === nftId).map(x=> console.log(x))
}
useEffect(() => {
fetchPost()
}, [])