Q&A
Reactの勉強中です。
React実践の教科書という本で勉強しているのですが、そのchapter9でつまづいています。
axios
1axios 2 .get("https://my-json-server.typicode.com/Goolaa/demo/users2") 3 .then((result) => { 4 const users = result.data.map((user) => ({ 5 id: user.id, 6 name: `${user.lastname} ${user.firstname}`, 7 age: user.age 8 })); 9 setUserList(users); 10 }) 11 .catch(() => setIsError(true)) 12 .finally(() => setIsLoading(false));
このロジックを動かすと、
error
1TypeError 2Cannot read properties of undefined (reading 'get')
となります。
ちなみに環境は、
https://codesandbox.io/s/vigilant-robinson-mdhfto?file=/src/App.jsx:329-711
get内のURLを実行すると、きちんと値が返ってきます。
URLからの返却
1[ 2 { 3 "id": 1, 4 "firstname": "勉", 5 "lastname": "主田", 6 "age": 24 7 }, 8 { 9 "id": 2, 10 "firstname": "未来", 11 "lastname": "先岡", 12 "age": 28 13 }, 14 { 15 "id": 3, 16 "firstname": "一郎", 17 "lastname": "後藤", 18 "age": 23 19 } 20]
どなたか、getでエラーにならない方法をお教えください。
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2023/03/21 23:10