I am trying to add weather to my app, so installed a weather package.
I created subscription key. I followed the exact steps.
But still I am getting the error, can you tell me how to fix it.
Providing my code snippet and sandbox
React package https://github.com/farahat80/react-open-weather#readme
https://codesandbox.io/s/n6ssk7?file=/src/App.js
function App() {
const { data2, isLoading, errorMessage } = useOpenWeather({
key: "<key>",
lat: "48.137154",
lon: "11.576124",
lang: "en",
unit: "metric" // values are (metric, standard, imperial)
});
console.log("data2", data2); // undefined
CodePudding user response:
Your error is that you are trying to get data2 from the object returned by the useOpenWeather function, when in fact what you have to do is rename it, try this code
const { data: data2, isLoading, errorMessage } = useOpenWeather({
key: "68c1eba48e8f3669646eed019c4aa0b1",
lat: "48.137154",
lon: "11.576124",
lang: "in",
unit: "metric" // values are (metric, standard, imperial)
});
console.log("data2", data2, isLoading, errorMessage);
