質問編集履歴

1

誤字の修正

2023/01/30 15:51

投稿

jack20xx
jack20xx

スコア45

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
  undefined is not an object というエラーが出ました。
5
5
  おそらくgetWeatherDataでAPIからデータを持ってくる処理が完了する前に
6
6
  whether.sys.sunrise という宣言を行おうとしているせいで、エラーが起きていると思われます。
7
- APIからデータを持てくる際にこのような宣言を行いたい場合、どのようにすれば成功するでしょうか?
7
+ APIからデータを持てくる際にこのような宣言を行いたい場合、どのようにすれば成功するでしょうか?
8
8
 
9
9
  ### 実現したいこと
10
10
 
@@ -22,49 +22,30 @@
22
22
  ```ここに言語名を入力
23
23
 
24
24
  〜〜〜〜〜〜〜〜〜〜
25
- export const HomeScreen = (props) => {
25
+ export const AddressScreen = () => {
26
- const {navigation} = props;
27
- const [city, setCity] = useState('');
28
- const [weather, setWeather] = useState('');
26
+ const [address, setAddress] = useState('');
29
27
 
30
28
  const baseURL = `${APIKey}`
31
29
 
32
- const getWeatherData = () => {
30
+ const getAddressData = () => {
33
31
  axios.get(baseURL)
34
- .then((response) => {setWeather(response.data)})
32
+ .then((response) => {setAddress(response.data)})
35
33
  .catch(error => console.log(error))
36
34
  };
37
35
 
38
36
  const sunrise = new Date(weather.sys.sunrise * 1000); //エラー箇所
39
- const sunset = new Date(weather.sys.sunset * 1000); //エラー箇所
40
37
  const sunriseTime = sunrise.toLocaleTimeString();
41
- const sunsetTime = sunset.toLocaleTimeString();
42
38
 
43
39
  return (
44
- <KeyboardAvoidingView style={styles.container} behavior="height">
40
+ <KeyboardAvoidingView>
45
41
  〜〜〜〜〜〜〜〜
46
- <View style={styles.subInfo}>
47
- {weather ? (
42
+ <View>
48
- <View style={styles.subInfoInner}>
49
- <View style={styles.subInfoContent}>
50
- <Text style={styles.subText}>
43
+ <Text>
51
- Max: {Math.round(weather.main.temp_max * 10) / 10}℃
44
+ Sunrise: {(sunriseTime)} //関係している箇所
52
- </Text>
45
+ </Text>
53
- <Text style={styles.subText}>
54
- Humidity: {Math.round(weather.main.humidity * 10) / 10}%
55
- </Text>
56
- <Text style={styles.subText}>
57
- Sunrise: {(sunriseTime)} //関係している箇所
58
- </Text>
59
- </View>
60
- </View>
61
- ) : (
62
- <Text>Error</Text>
63
- )}
64
46
  </View>
65
47
  </KeyboardAvoidingView>
66
48
  );
67
- };
68
49
 
69
50
  ```
70
51
  ### 補足情報