adrianhajdin / project_travel_advisor

Tutorial created in collaboration with Enyel Sequeira, taught by JavaScript Mastery.
MIT License
2.03k stars 445 forks source link

issue in App.js #12

Open Ras443 opened 2 years ago

Ras443 commented 2 years ago

error

andyriles commented 2 years ago

use optional chaining on your data array

Ras443 commented 2 years ago

Can you eloborate that?

andyriles commented 2 years ago

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

abhijain2003 commented 2 years ago

go and checkout i did it

16030IT028 commented 2 years ago

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

16030IT028 commented 2 years ago

go and checkout i did it

still I was facing same issue, can u help me to fix it

LorsHim66 commented 1 year ago

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);`