Created
February 5, 2018 06:09
-
-
Save ichiroku11/61f5bdc7ba683dd9387d921a42017b22 to your computer and use it in GitHub Desktop.
fetchとasync/awaitのサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // fetchを使ってjsonを読み込む | |
| const testAsync = async () => { | |
| const response = await fetch("sample.json"); | |
| // sample.json | |
| // { "message": "Hello, World!" } | |
| const json: { message: string; } = await response.json(); | |
| console.log(json.message); | |
| // Hello, World! | |
| }; | |
| testAsync(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment