回答編集履歴
3
不要部分をカット
test
CHANGED
@@ -8,17 +8,7 @@
|
|
8
8
|
|
9
9
|
// fetchをreturnしているので戻って来るのはPromise
|
10
10
|
|
11
|
-
const fn = () => {
|
12
|
-
|
13
|
-
|
11
|
+
const fn = () => fetch('https://facebook.github.io/react-native/movies.json');
|
14
|
-
|
15
|
-
.then((response) => {
|
16
|
-
|
17
|
-
return response;
|
18
|
-
|
19
|
-
});
|
20
|
-
|
21
|
-
}
|
22
12
|
|
23
13
|
|
24
14
|
|
2
誤字を修正
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
```
|
8
8
|
|
9
|
-
// fetchをreturn
|
9
|
+
// fetchをreturnしているので戻って来るのはPromise
|
10
10
|
|
11
11
|
const fn = () => {
|
12
12
|
|
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
-
// fn
|
25
|
+
// fnのリターンはPromiseなのでresにはPromiseが入る
|
26
26
|
|
27
27
|
const test1 = () => {
|
28
28
|
|
@@ -34,7 +34,7 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
-
// fn
|
37
|
+
// fnから返って来たPromiseをawaitすることでfetchの結果がresに入る
|
38
38
|
|
39
39
|
const test2 = async () => {
|
40
40
|
|
1
実行結果を載せ忘れたので追記。
test
CHANGED
@@ -46,6 +46,22 @@
|
|
46
46
|
|
47
47
|
```
|
48
48
|
|
49
|
+
実行結果
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
test1();
|
54
|
+
|
55
|
+
async Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
test2();
|
60
|
+
|
61
|
+
sync Response {type: "cors", url: "https://facebook.github.io/react-native/movies.json", redirected: false, status: 200, ok: true, …}
|
62
|
+
|
63
|
+
```
|
64
|
+
|
49
65
|
|
50
66
|
|
51
67
|
Promiseというのは約束(予約)なので
|