{"id":392,"date":"2017-08-09T15:15:07","date_gmt":"2017-08-09T06:15:07","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2017\/08\/09\/redux-with-rest-api"},"modified":"2017-08-09T15:15:07","modified_gmt":"2017-08-09T06:15:07","slug":"redux-with-rest-api","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2017\/08\/09\/redux-with-rest-api\/","title":{"rendered":"Redux\u3092REST API\u3068\u4f7f\u3046\u6642\u306e\u547d\u540d\u306e\u30b3\u30c4"},"content":{"rendered":"
\u4eca\u56de\u306f\u3001REST API\u306b\u5bfe\u3057\u3066Redux\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306e\u547d\u540d\u306e\u30b3\u30c4\u3092\u66f8\u3044\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3046\u3002<\/p>\n
\u524d\u6e96\u5099\u3068\u3057\u3066\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u72b6\u614b\u3092\u8868\u3059constants\u3092\u3064\u304f\u3063\u3066\u304a\u304f\u3002<\/p>\n
\u57fa\u672c\u7684\u306bREST API\u3092\u6271\u3046\u6642\u306f\u3001\u30ed\u30b8\u30c3\u30af\u5074\u306fAPI\u30ea\u30bd\u30fc\u30b9\u306b\u5408\u308f\u305b\u305f\u547d\u540d\u306b\u3057\u3066\u304a\u304f\u3002\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u306e\u4e16\u754c\u3068\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u5207\u308a\u66ff\u3048\u308b\u3053\u3068\u306a\u304f\u4f5c\u696d\u3067\u304d\u3066\u3001\u6df7\u4e71\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u4f8b\u3048\u3070\u3001\u30e6\u30fc\u30b6\u30fc\u4e00\u89a7\u3092\u53d6\u5f97\u3059\u308b Redux\u3067\u975e\u540c\u671f\u306a\u51e6\u7406\u3092\u6271\u3046\u6642\u306f\u3001 \u3053\u308c\u304c\u3042\u308b\u3068\u3001 \u30e6\u30fc\u30b6\u30fc\u4e00\u89a7\u3092\u3064\u304f\u308b \u6ce8\u610f\u70b9\u3068\u3057\u3066\u306f\u3001\u3053\u3053\u3067\u306e \u4f8b\u3048\u3070\u3001\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8 \u3053\u306e\u5834\u5408\u3001\u30d3\u30e5\u30fc\u306b\u306f\u5358\u4e00\u306e\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u306e\u307f\u304c\u8868\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u6295\u5f71\u3059\u308b\u30e2\u30c7\u30eb\u306f\u3001\/users<\/code>\u3068\u3044\u3046\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u304c\u3042\u308c\u3070\u3001
users<\/code>\u3068\u3044\u3046\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u5168\u4f53\u3092\u8a2d\u8a08\u3057\u3066\u3086\u304f\u3002<\/p>\n
\u30ea\u30af\u30a8\u30b9\u30c8\u4e2d<\/code>
\u30ea\u30af\u30a8\u30b9\u30c8\u6210\u529f<\/code>
\u30ea\u30af\u30a8\u30b9\u30c8\u5931\u6557<\/code>\u306e\u3088\u3046\u306a\u72b6\u614b\u3092\u6301\u3063\u3066\u304a\u304f\u3068\u601d\u3046\u304c\u3001REST API\u306e\u5834\u5408\u3001\u3053\u308c\u306b
GET<\/code>
POST<\/code>
PUT<\/code>
DELETE<\/code>\u306a\u3069\u304c\u306e\u3063\u3066\u304f\u308b\u306e\u3067\u3001\u547d\u540d\u3067\u6df7\u4e71\u3057\u306a\u3044\u3088\u3046\u306b\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30d8\u30eb\u30d1\u30fc\u3092\u4f5c\u3063\u3066\u304a\u304f\u3002<\/p>\n
const createAsyncConstants = (constant: string): TAsyncConstants => (\n {\n REQUEST: constant,\n SUCCESS: `${constant}_SUCCESS`,\n FAILURE: `${constant}_FAILURE`,\n }\n);\n\nexport const createRESTConstants = (constant: string): TRESTConstants => (\n {\n GET: createAsyncConstants(`${constant}_GET`),\n POST: createAsyncConstants(`${constant}_POST`),\n PUT: createAsyncConstants(`${constant}_PUT`),\n DELETE: createAsyncConstants(`${constant}_DELETE`),\n }\n);\n\nexport const USERS = createRESTConstants('USERS'); \/\/ \u4f7f\u7528\u4f8b<\/code><\/pre>\n
export const USERS = createRESTConstants('USERS');<\/code>\u306e\u3088\u3046\u306b\u66f8\u304f\u3060\u3051\u3067\u3001
USERS.GET.REQUEST<\/code>
USERS.GET.SUCCESS<\/code>
USERS.GET.FAILURE<\/code>\u306e\u3088\u3046\u306b\u305d\u308c\u305e\u308c\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u5bfe\u5fdc\u3057\u305f\u975e\u540c\u671f\u306e\u72b6\u614b\u3092\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u578b\u304c\u3064\u304f\u3068\u30b5\u30b8\u30a7\u30b9\u30c1\u30e7\u30f3\u304c\u3067\u308b\u306e\u3067\u66f8\u304d\u9593\u9055\u3048\u308b\u3053\u3068\u3082\u306a\u3044\u3002<\/p>\n
Redux\u306estate\u8a2d\u8a08\u3092\u3059\u308b<\/h2>\n
state<\/code>\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n
const defaultUsers: TDefaultUsers = {\n items: [],\n query: {\n name: '',\n email: '',\n phoneNumber: '',\n type: '',\n emailVerifiedFlg: true,\n page: 1,\n },\n totalPage: 1,\n isLoading: false,\n errorMessage: '',\n};<\/code><\/pre>\n
users<\/code>\u3068\u3044\u3046\u547d\u540d\u306f\u3001\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8(
\/users<\/code>)\u306b\u3042\u308f\u305b\u305f\u3082\u306e\u3067\u306f\u306a\u3044<\/strong>\u3068\u3044\u3046\u3053\u3068\u3060\u3002\u3053\u3053\u306f\u30d3\u30e5\u30fc\u3067\u6271\u3044\u3084\u3059\u3044\u3088\u3046\u306a\u30e2\u30c7\u30eb\u3092\u8a2d\u8a08\u3059\u308b\u306e\u304c\u6b63\u89e3\u304b\u3068\u601d\u3046\u3002<\/p>\n
\/users<\/code>\u306e
POST<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u8003\u3048\u305f\u3068\u304d\u306b\u3001\u5358\u4e00\u306e\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u6210\u3059\u308b\u30d5\u30a9\u30fc\u30e0\u753b\u9762\u304c\u3042\u308b\u3068\u60f3\u5b9a\u3059\u308b\u3002<\/p>\n
users<\/code>\u3067\u306f\u306a\u304f\u3001
user<\/code>\u3067\u3042\u308a\u3001\u30d5\u30a9\u30fc\u30e0\u306e\u30c7\u30fc\u30bf\u306f\u305d\u308c\u3092\u69cb\u6210\u3059\u308b\u30af\u30a8\u30ea\u306b\u306a\u308b\u306e\u3067\u306f\u306a\u3044\u3060\u308d\u3046\u304b\u3002
state<\/code>\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u305d\u3046\u3060\u3002<\/p>\n
const defaultUser: TDefaultUser = {\n query: {\n name: '',\n email: '',\n phoneNumber: '',\n type: '',\n emailVerifiedFlg: true,\n },\n isLoading: false,\n errorMessage: '',\n};<\/code><\/pre>\n