-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
お魚リストを取得して一覧表示するコンポーネントの追加 #11
Conversation
Azure Static Web Apps: Your stage site is ready! Visit it here: https://kind-smoke-0c29e3100-11.eastasia.1.azurestaticapps.net |
Azure Static Web Apps: Your stage site is ready! Visit it here: https://kind-smoke-0c29e3100-11.eastasia.1.azurestaticapps.net |
Azure Static Web Apps: Your stage site is ready! Visit it here: https://kind-smoke-0c29e3100-11.eastasia.1.azurestaticapps.net |
Azure Static Web Apps: Your stage site is ready! Visit it here: https://kind-smoke-0c29e3100-11.eastasia.1.azurestaticapps.net |
Azure Static Web Apps: Your stage site is ready! Visit it here: https://kind-smoke-0c29e3100-11.eastasia.1.azurestaticapps.net |
Azure Static Web Apps: Your stage site is ready! Visit it here: https://kind-smoke-0c29e3100-11.eastasia.1.azurestaticapps.net |
Azure Static Web Apps: Your stage site is ready! Visit it here: https://kind-smoke-0c29e3100-11.eastasia.1.azurestaticapps.net |
Azure Static Web Apps: Your stage site is ready! Visit it here: https://kind-smoke-0c29e3100-11.eastasia.1.azurestaticapps.net |
resolved: #16
Reactでどうしてもお魚を釣りたい(意訳)
単にReactからAPIを叩いてお魚データを取得するだけのソースコードです。
CosmosDB(データベース)
CosmosDBには以下のお魚データが入っています。
Node.js(バックエンド)
api/FishesRead/index.ts
CosmosDBから
context.bindings.documents
を介してfishesのデータを全て取得しています。api/FishesRead/function.json
context.bindings.documents
の定義はapi/FishesRead/function.json
のbindings
の中にあります。実際にCosmosDBとやり取りするためには
api
ディレクトリにlocal.settings.json
を置く必要があります。内容は @yukinissie に聞いてください。シークレットなファイルになります。React(フロントエンド)
src/components/Fishes.tsx
お魚データを取得中はローディングコンポーネントを表示します。
src/hooks/useFetch.ts
useFetch
はこの記事をめちゃくちゃ参考にしました。src/types/Fish.ts
APIがどのような値を返すことを期待しているかこのファイルで宣言しています。
src/componets/FishList.tsx
ちなみに表示に使用するFishListコンポーネントはこのようなコードになっています。
受け取ったお魚データの数だけリストにして返しているだけです。