質問編集履歴
2
コードの変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
APIから取得したデータを整形して返すコードなのですが、繰り返しが多くて冗長な感じがします。
|
2
2
|
一度に変数`book`の中に必要なデータを入れることはできないでしょうか?
|
3
3
|
|
4
|
+
※コード修正しました
|
4
5
|
```js
|
6
|
+
export const fetchBookByIsbn = async isbnInput => {
|
7
|
+
const url = `https://app.rakuten.co.jp/services/api/BooksBook/Search/20170404?applicationId=${rakutenAppId}&isbn=${isbnInput}`;
|
8
|
+
|
9
|
+
const response = await fetch(url);
|
10
|
+
const data = await response.json();
|
11
|
+
const bookData = data.Items.map(val => val.Item)[0];
|
5
12
|
const {
|
6
13
|
isbn,
|
7
14
|
title,
|
@@ -11,4 +18,6 @@
|
|
11
18
|
} = bookData;
|
12
19
|
const book = { isbn, title, author, publisherName, coverImageUrl };
|
13
20
|
return book;
|
21
|
+
};
|
22
|
+
|
14
23
|
```
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
APIから取得したデータを整形して返すコードなのですが、繰り返しが多く冗長な感じがします。
|
1
|
+
APIから取得したデータを整形して返すコードなのですが、繰り返しが多くて冗長な感じがします。
|
2
2
|
一度に変数`book`の中に必要なデータを入れることはできないでしょうか?
|
3
3
|
|
4
4
|
```js
|