I'm in react Native, and I have a request that im making using axios, and the request is supposed to return something like this: Json data
I want to be able to save only the "Products" array in a variable. This is the snippet of my cod, but it's giving me a 'Possible unhandled promise rejection' and I dont understand why:
const [shoesData, setShoesData] = useState([]);
useEffect(() => {
const getShoesData = async () => {
await axios.get("https://stockx.com/api/browse?productCategory=sneakers&sort=release_date&releaseTime=gte-" Date.now().toLocaleString() "&order=ASC&country=FR")
.then(response => {
let products = response.data.map(x => {
return x.products;
});
setShoesData(products);
console.log(products);
})
}
getShoesData();
}, [])
Thanks in advance for your help.
CodePudding user response:
Try and wrap your await instruction with a try catch. One possible error can be that the data you get from the response can, in some cases, not have a products field.