import { useEffect, useReducer } from 'react'; const initialState = { loading: false, // データ取得中はtrueに設定される error: null, // データ取得でエラーになると設定される data: null, // データ取得結果が設定される }; const reducer = (state, action) => { switch (action.type) { case 'init': // 初期状態に戻す return initialState; case 'start': // データ取得を開始する return { ...state, loading: true }; case 'data': // データ取得が正常終了する return { ...state, loading: