Skip to content

Commit f7120cf

Browse files
committed
Fix weather app loading bug
1 parent bb48816 commit f7120cf

File tree

1 file changed

+14
-14
lines changed
  • ch7_WeatherApp/src/Screens/WeatherView

1 file changed

+14
-14
lines changed

ch7_WeatherApp/src/Screens/WeatherView/index.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { useEffect, useState } from 'react';
2-
import { FlatList, Alert } from 'react-native';
1+
import React, {useEffect, useState} from 'react';
2+
import {FlatList, Alert} from 'react-native';
33
import Geolocation from 'react-native-geolocation-service';
44

55
import Styled from 'styled-components/native';
@@ -46,7 +46,7 @@ interface IWeather {
4646
weather?: string;
4747
isLoading: boolean;
4848
}
49-
const WeatherView = ({ }: Props) => {
49+
const WeatherView = ({}: Props) => {
5050
const [weatherInfo, setWeatherInfo] = useState<IWeather>({
5151
temperature: undefined,
5252
weather: undefined,
@@ -58,32 +58,32 @@ const WeatherView = ({ }: Props) => {
5858
isLoading: false,
5959
});
6060
Geolocation.getCurrentPosition(
61-
position => {
62-
const { latitude, longitude } = position.coords;
61+
(position) => {
62+
const {latitude, longitude} = position.coords;
6363
fetch(
64-
`http://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&APPID=${API_KEY}&units=metric`
64+
`http://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${API_KEY}&units=metric`,
6565
)
66-
.then(response => response.json())
67-
.then(json => {
66+
.then((response) => response.json())
67+
.then((json) => {
6868
setWeatherInfo({
6969
temperature: json.main.temp,
7070
weather: json.weather[0].main,
7171
isLoading: true,
7272
});
7373
})
74-
.catch(error => {
74+
.catch((error) => {
7575
setWeatherInfo({
7676
isLoading: true,
7777
});
7878
showError('날씨 정보를 가져오는데 실패하였습니다.');
7979
});
8080
},
81-
error => {
81+
(error) => {
8282
setWeatherInfo({
8383
isLoading: true,
8484
});
8585
showError('위치 정보를 가져오는데 실패하였습니다.');
86-
}
86+
},
8787
);
8888
};
8989

@@ -98,7 +98,7 @@ const WeatherView = ({ }: Props) => {
9898
}, []);
9999

100100
let data = [];
101-
const { isLoading, weather, temperature } = weatherInfo;
101+
const {isLoading, weather, temperature} = weatherInfo;
102102
if (weather && temperature) {
103103
data.push(weatherInfo);
104104
}
@@ -118,13 +118,13 @@ const WeatherView = ({ }: Props) => {
118118
<LoadingLabel>Loading...</LoadingLabel>
119119
</LoadingView>
120120
}
121-
renderItem={({ item, index }) => (
121+
renderItem={({item, index}) => (
122122
<WeatherItemContainer>
123123
<Weather>{(item as IWeather).weather}</Weather>
124124
<Temperature>({(item as IWeather).temperature}°C)</Temperature>
125125
</WeatherItemContainer>
126126
)}
127-
contentContainerStyle={{ flex: 1 }}
127+
contentContainerStyle={{flex: 1}}
128128
/>
129129
</Container>
130130
);

0 commit comments

Comments
 (0)