前提
fetch()で取得したjsonを扱いたい。
実現したいこと
getData関数で取得したjsonを関数の外で扱いたいです。
getData().dataを実行すると以下のエラーメッセージが出力されます。
TypeError: Cannot read properties of undefined(reading "data")
該当のソースコード
getData() { const url = "https://umayadia-apisample.azurewebsites.net/api/persons/Shakespeare"; fetch(url) .then(res => res.json()) .then(data => { return data; }) };

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。