Hello i am trying to fetch weather data from api and im struggling i have the not a function error. Here is my code https://codesandbox.io/s/react-weather-app-ptlnoq?file=/src/App.js
#fetch nested datas
9 messages · Page 1 of 1 (latest)
U did not define weatherItem in any part of ur code before u console log it.. that’s why it’s showing weatherItem is not defined error.. can u tell me more what are you trying to console log? If u want to console log the data u just fetch, u should use weatherData
That was Just a test but when i map weatherData i have undefined function
I’m sorry I don’t understand what u are talking about.. Can u tell me more?
i want to access my data i just fetched in the effect so i use the weatherData but when i type weather.main.temp i have an error so i tried to map weatherData and i have not a function error (look the sandbox and the screenshot of the data)
i fixed ur code alil bit. I made useState({}) instead of useState([]) because the data we fetched is an object. anyway the data becomes 'weatherData'. so we can access weatherData.main.temp for the temperature as in the screenshot i attached. here is the sandbox i forked from you https://codesandbox.io/s/react-weather-app-forked-kltwo2?file=/src/App.js. Let me know if you get the answer you wanted.
yes its working but when i refresh i have the error Cannot read properties of undefined (reading '0')
Try this link. Read the comments. I tried to explain as best I could. It might not be everything, but it works with what you are trying to do.
https://codesandbox.io/s/react-weather-app-forked-jkcchi?file=/src/App.js
thank you so much 🙂