Open Ras443 opened 2 years ago
use optional chaining on your data array
Can you eloborate that?
Rather than data.filter, do data?.filter. Sometimes your internet might be slow, so data which you're fetching might not arrive when immediately. So when you run data.filter, since data would be currently empty, you can't filter an empty or nonexistent array, so it would throw an error. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
go and checkout i did it
Rather than data.filter, do data?.filter. Sometimes your internet might be slow, so data which you're fetching might not arrive when immediately. So when you run data.filter, since data would be currently empty, you can't filter an empty or nonexistent array, so it would throw an error. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
still I was facing same issue, can u help me to fix it
go and checkout i did it
still I was facing same issue, can u help me to fix it
Hello Sire Can u help me to fix this problem?
st.js:12 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')
` .then((data) => setWeatherData(data)); 42 | getPlacesData(type, bounds.sw, bounds.ne) 43 | .then((data) => {
44 | setPlaces(data?.filter((place) => place.name && place.num_reviews > 0)); | ^ 45 | setFilteredPlaces([]); 46 | setRating(''); 47 | setIsLoading(false);`