{"id":1559,"date":"2017-04-13T12:05:13","date_gmt":"2017-04-13T03:05:13","guid":{"rendered":"http:\/\/lovelinux.mydns.jp\/?p=1559"},"modified":"2017-04-13T12:15:52","modified_gmt":"2017-04-13T03:15:52","slug":"react%e3%80%81redux%e5%85%a5%e9%96%80-%e5%85%ac%e5%bc%8f%e3%82%b5%e3%82%a4%e3%83%88%e3%81%a8%e3%81%af%e3%81%a1%e3%82%87%e3%81%a3%e3%81%a8%e9%81%95%e3%81%86%e8%a7%92%e5%ba%a6%e3%81%8b%e3%82%89-2","status":"publish","type":"post","link":"https:\/\/lovelinux.mydns.jp\/?p=1559","title":{"rendered":"React\u3001Redux\u5165\u9580 \u516c\u5f0f\u30b5\u30a4\u30c8\u3068\u306f\u3061\u3087\u3063\u3068\u9055\u3046\u89d2\u5ea6\u304b\u3089"},"content":{"rendered":"<h3>\u306f\u3058\u3081\u306b<\/h3>\n<p>\u3053\u30533\u9031\u9593\u307b\u3069\u6b7b\u306c\u307b\u3069React\u3068Redux\u3084\u3063\u3066\u3001\u3042\u308c\u3053\u308c\u5206\u304b\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u3053\u308c\u304b\u3089React+Redux\u3067\u958b\u767a\u3092\u59cb\u3081\u305f\u3044\u4eba\u5411\u3051\u306b\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u307f\u307e\u3059\u3002<br \/>\n\u516c\u5f0f\u30b5\u30a4\u30c8\u306e\u82f1\u8a9e\u8a18\u4e8b\u3084\u3001\u305d\u308c\u3092\u7ffb\u8a33\u3057\u3066\u304f\u308c\u3066\u3044\u308b\u3088\u3046\u306a\u30b5\u30a4\u30c8\u3092\u898b\u3066\u3082\u305d\u308c\u306a\u308a\u306b\u5206\u304b\u308b\u306e\u3067\u3059\u304c\u30fb\u30fb\u30fb<br \/>\n\u306a\u3093\u3060\u304b\u3093\u3060\u8a00\u3063\u3066\u96e3\u3057\u3044\u3002<br \/>\nReact\u306e\u7406\u89e3\u306f\u306a\u3093\u3068\u304b\u51fa\u6765\u3066\u3082\u3001Redux\u304c\u7279\u306b\u96e3\u3057\u3044\u3002<\/p>\n<p>\u6b32\u5f35\u308a\u306a\u3093\u3067\u3059\u304c\u3001\u3068\u306b\u304b\u304f\u4e21\u65b9\u3092\u30b5\u30fc\u30c3\u3068\u7406\u89e3\u3057\u3066\u3001\u3055\u3063\u3055\u3068\u30a2\u30d7\u30ea\u7d44\u307f\u305f\u3044\u3088\u3068\u3044\u3046\u65b9\u306e\u52a9\u3051\u306b\u306a\u308c\u308c\u3070\u3068\u30fb\u30fb\u30fb<\/p>\n<h3>\u8003\u3048\u3066\u3044\u304f\u624b\u9806<\/h3>\n<ul>\n<li>\u753b\u9762\u30a4\u30e1\u30fc\u30b8<\/li>\n<li>\u753b\u9762\u3092\u69cb\u7bc9\u3059\u308b\u305f\u3081\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u968e\u5c64\u56f3<\/li>\n<li>\u30b9\u30c6\u30fc\u30c8<\/li>\n<li>\u30a4\u30d9\u30f3\u30c8<\/li>\n<\/ul>\n<p>\u57fa\u672c\u7684\u306b\u3053\u306e\uff14\u3064\u3092\u8003\u3048\u308c\u3070OK\u3067\u3059\u3002<\/p>\n<p>\u65e2\u306b<a href=\"http:\/\/lovelinux.mydns.jp\/?p=1553\">\u5225\u306e\u8a18\u4e8b\u3067\u66f8\u3044\u3066\u3044\u308b\u3000Rails\u3068React\u3068Redux\u3092\u7d44\u307f\u5408\u308f\u305b\u305f\u63b2\u793a\u677f\u30a2\u30d7\u30ea<\/a>\u306e\u753b\u9762\u3092\u4f8b\u306b\u3068\u3063\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u4f5c\u308b\u30a2\u30d7\u30ea\u306e\u753b\u9762\u30a4\u30e1\u30fc\u30b8\u3092\u982d\u306e\u4e2d\u3067\u69cb\u7bc9\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u7d19\u306b\u7d75\u3092\u66f8\u3044\u3066\u307f\u305f\u308a\u3059\u308b\u3068\u3044\u3044\u3067\u3059\u306d\u3002<br \/>\n\u3053\u306e\u4f8b\u306e\u5834\u5408\u306f\u3001\u753b\u9762\u306f\u81f3\u3063\u3066\u30b7\u30f3\u30d7\u30eb\u3002\u753b\u9762\u5de6\u5074\u306b\u63b2\u793a\u677f\u4e00\u89a7\u304c\u30ea\u30b9\u30c8\u30a2\u30c3\u30d7\u3055\u308c\u3066\u3044\u3066\u3001\u305d\u306e\u63b2\u793a\u677f\u306e\u3069\u308c\u304b\u3092\u9078\u629e\u3059\u308b\u3068\u3001\u753b\u9762\u53f3\u5074\u306b\u63b2\u793a\u677f\u306b\u6295\u7a3f\u3055\u308c\u305f\u30b3\u30e1\u30f3\u30c8\u4e00\u89a7\u304c\u5217\u6319\u3055\u308c\u308b\u3002<br \/>\n\u753b\u9762\u53f3\u4e0a\u3067\u306f\u3001\u63b2\u793a\u677f\u306b\u65b0\u305f\u306b\u30b3\u30e1\u30f3\u30c8\u3092\u6295\u7a3f\u3067\u304d\u308b\u3002\u3053\u3093\u306a\u3082\u306e\u3002<\/p>\n<p><a href=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/react-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/react-1-1024x432.png\" alt=\"react-1\" width=\"806\" height=\"340\" class=\"alignnone size-large wp-image-1524\" srcset=\"https:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/react-1.png 1024w, https:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/react-1-300x127.png 300w, https:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/react-1-768x324.png 768w\" sizes=\"auto, (max-width: 806px) 100vw, 806px\" \/><\/a><\/p>\n<p>\u3053\u306e\u753b\u9762\u3092\u69cb\u6210\u3059\u308b\u30d1\u30fc\u30c4\u3092React\u98a8\u306b\u8003\u3048\u3066\u307f\u308b\u3068\u3001\u3056\u3063\u3068\u3053\u3093\u306a\u611f\u3058\u3002<br \/>\n\u3053\u308c\u304c\u300c\u753b\u9762\u3092\u69cb\u7bc9\u3059\u308b\u305f\u3081\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u968e\u5c64\u56f3\u300d\u3002<br \/>\n<a href=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/react-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/react-2-1024x478.png\" alt=\"react-2\" width=\"806\" height=\"376\" class=\"alignnone size-large wp-image-1523\" srcset=\"https:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/react-2.png 1024w, https:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/react-2-300x140.png 300w, https:\/\/lovelinux.mydns.jp\/wp-content\/uploads\/2017\/04\/react-2-768x359.png 768w\" sizes=\"auto, (max-width: 806px) 100vw, 806px\" \/><\/a><\/p>\n<p>\u6b21\u3001\u30b9\u30c6\u30fc\u30c8\u3002<br \/>\n\u3053\u306e\u753b\u9762\u30a4\u30e1\u30fc\u30b8\u3092\u898b\u3066\u3001\u5909\u52d5\u3057\u305d\u3046\u306a\u3082\u306e\u3092\u8003\u3048\u308b\u3002<br \/>\n\u3056\u3063\u3068\u8003\u3048\u308b\u3068\u63b2\u793a\u677f\u4e00\u89a7\u3068\u3001\u30b3\u30e1\u30f3\u30c8\u4e00\u89a7\u3001\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677f\u3001\u30e6\u30fc\u30b6\u30fc\u4e00\u89a7\u3000\u3050\u3089\u3044\u3002<\/p>\n<p>\u30e6\u30fc\u30b6\u30fc\u4e00\u89a7\u304c\u306a\u3093\u3067\u5fc5\u8981\u304b\u3068\u3044\u3046\u3068\u3001\u3053\u306e\u30a2\u30d7\u30ea\u3067\u306f\u8aac\u660e\u3092\u7c21\u5358\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u30ed\u30b0\u30a4\u30f3\u51e6\u7406\u306a\u3069\u8a2d\u3051\u305a\u306b\u3001\u6295\u7a3f\u3059\u308b\u969b\u306b\u300c\u81ea\u5206\u306f\u8ab0\u3005\u3067\u3059\u3088\u300d\u3068\u9078\u629e\u3057\u3066\u3001\u30b3\u30e1\u30f3\u30c8\u3092\u6295\u7a3f\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u3067\u3001\u4e0a\u8a18\u306e\uff14\u3064\u304c\u672c\u5f53\u306b\u30b9\u30c6\u30fc\u30c8\u304b\u8003\u3048\u308b\u3002<br \/>\n\u3088\u304f\u8003\u3048\u3066\u307f\u308b\u3068\u3001\u63b2\u793a\u677f\u4e00\u89a7\u306f\u8ffd\u52a0\u3067\u304d\u308b\u6a5f\u80fd\u304c\u306a\u3044\u306e\u3067\u3001\u521d\u671f\u5024\u56fa\u5b9a\u306e\u307e\u307e\u3002\u30e6\u30fc\u30b6\u30fc\u4e00\u89a7\u3082\u521d\u671f\u5024\u56fa\u5b9a\u306e\u307e\u307e\u3002<br \/>\n\u3088\u3063\u3066\u3053\u306e\uff12\u3064\u306f\u30b9\u30c6\u30fc\u30c8\u3068\u306f\u8003\u3048\u306a\u3044\u3002<\/p>\n<p>\u3058\u3083\u3042\u3001\u30b9\u30c6\u30fc\u30c8\u3068\u3057\u3066\u6b8b\u308b\u306e\u306f<\/p>\n<ul>\n<li>\u30b3\u30e1\u30f3\u30c8\u4e00\u89a7<\/li>\n<li>\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677f<\/li>\n<\/ul>\n<p>\u306e\uff12\u3064\u3060\u3051\u3002<\/p>\n<p>\u6b21\u3001\u30a4\u30d9\u30f3\u30c8\u3002<\/p>\n<p>\u3053\u308c\u306f\u3059\u3050\u89e3\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u63b2\u793a\u677f\u4e00\u89a7\u304b\u3089\u3069\u308c\u304b\u3092\u9078\u629e\u3059\u308b<\/li>\n<li>\u63b2\u793a\u677f\u306b\u30b3\u30e1\u30f3\u30c8\u3092\u6295\u7a3f\u3059\u308b<\/li>\n<\/ul>\n<p>\u3053\u306e\uff12\u3064\u3060\u3051\u3002<\/p>\n<h3>\u3069\u3046\u3084\u3063\u3066\u30a2\u30d7\u30ea\u3092\u7d44\u307f\u4e0a\u3052\u3066\u3044\u304f\u304b<\/h3>\n<ul>\n<li>\u753b\u9762\u30a4\u30e1\u30fc\u30b8<\/li>\n<li>\u753b\u9762\u3092\u69cb\u7bc9\u3059\u308b\u305f\u3081\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u968e\u5c64\u56f3<\/li>\n<li>\u30b9\u30c6\u30fc\u30c8<\/li>\n<li>\u30a4\u30d9\u30f3\u30c8<\/li>\n<\/ul>\n<p>\u8003\u3048\u308b\u624b\u9806\u3067\u3053\u308c\u306f\u3067\u304d\u305f\u306e\u3067\u3001\u3069\u3053\u304b\u3089\u304b\u624b\u3092\u4ed8\u3051\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u753b\u9762\u304b\u3089\u5148\u306b\u4f5c\u308a\u305f\u304f\u306a\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u3042\u308c\u3053\u308c\u3084\u3084\u3053\u3057\u304f\u306a\u308b\u306e\u3067<br \/>\n\u30a2\u30d7\u30ea\u306e\u30c8\u30c3\u30d7\u306b\u306a\u308bApp.js\u3000\u3050\u3089\u3044\u3060\u3051\u4f5c\u3063\u3066\u3001\u305d\u3053\u306bHelloWorld\u3050\u3089\u3044\u3092\u51fa\u3059\u3060\u3051\u306b\u3057\u3066\u3001<br \/>\n\u5148\u306b\u30c7\u30fc\u30bf\u69cb\u9020\u3068\u30a4\u30d9\u30f3\u30c8\u306e\u90e8\u5206\u3092\u8003\u3048\u307e\u3057\u3087\u3046\u3002\u305f\u3076\u3093\u3053\u308c\u304cRedux\u98a8\u306a\u8003\u3048\u65b9\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u69cb\u9020\u3068\u306f\u3064\u307e\u308a\u30b9\u30c6\u30fc\u30c8\u306e\u3053\u3068\u3002\u30c7\u30fc\u30bf\u69cb\u9020\u304c\u5909\u5316\u3059\u308b\u3068\u304d\u306f\u3069\u3093\u306a\u6642\u304b\u3068\u3044\u3046\u3068\u30a4\u30d9\u30f3\u30c8\u304c\u767a\u751f\u3057\u305f\u6642\u3002<br \/>\n\u3068\u306a\u308b\u306e\u3067\u3001\u307e\u305a\u30a4\u30d9\u30f3\u30c8\u4e00\u89a7\uff08ActionCreator\uff09\u3092\u4f5c\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>actions\/index.js<br \/>\n[bash]<br \/>\nexport const board_select = (id) => {<br \/>\n  return {<br \/>\n    type: &#8220;BOARD_SELECT&#8221;,<br \/>\n    id: id<br \/>\n  }<br \/>\n}<\/p>\n<p>export const comment_read = (comments) => {<br \/>\n  return {<br \/>\n    type: &#8220;COMMENT_READ&#8221;,<br \/>\n    comments: comments<br \/>\n  }<br \/>\n}<\/p>\n<p>[\/bash]<\/p>\n<p>\u3053\u3053\u3067\u306f\uff12\u3064\u306efunction\u3092\u4f5c\u3063\u3066\u3001\u305d\u306econst(function)\u3092export \u3057\u3066\u307e\u3059\u3002<br \/>\nfunction\u306e\u623b\u308a\u5024\u304c action\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3002<br \/>\n\u3061\u3087\u3063\u3068\u96e3\u3057\u304f\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u306d\u3002\u3068\u308a\u3042\u3048\u305a\u3001action\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u306fType\u30d7\u30ed\u30d1\u30c6\u30a3\u3092<br \/>\n\u5fc5\u305a\u4f5c\u308a\u3001\u305d\u3053\u306b\u3069\u3093\u306a\u30a4\u30d9\u30f3\u30c8\u304b\u8b58\u5225\u3067\u304d\u308b\u6587\u5b57\u5217\u3092\u30bb\u30c3\u30c8\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\n\u305d\u3057\u3066\u3001type\u4ee5\u5916\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u30a4\u30d9\u30f3\u30c8\u3067\u767a\u751f\u3057\u305f\u3042\u3068\u306b\u5909\u5316\u3059\u308b\u5024\u3092\u5217\u6319\u3057\u307e\u3059\u3002<\/p>\n<p>BOARD_SELECT \u3064\u307e\u308a\u3001\u63b2\u793a\u677f\u304c\u9078\u629e\u3055\u308c\u305f\u3089\u3001\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677fID\u304c\u5909\u308f\u308b\u306e\u3067\u3001<br \/>\nid\u3000\u3092\u30bb\u30c3\u30c8\u3057\u3066\u304a\u304f\u3068\u3044\u3046\u3088\u3046\u306a\u611f\u3058\u3002<\/p>\n<p>\u6b21\u3001\u30a4\u30d9\u30f3\u30c8\u304c\u767a\u751f\u3057\u305f\u3042\u3068\u3001\u5b9f\u969b\u306b\u30c7\u30fc\u30bf(public\u5909\u6570\u307f\u305f\u3044\u306a\u30a4\u30e1\u30fc\u30b8\uff09\u3092\u5909\u66f4\u3059\u308b\u3068\u3053\u308d\u3092\u4f5c\u308a\u307e\u3059\u3002<br \/>\n\u305d\u306e\u5834\u6240\u304creducer\u3067\u3059\u3002<\/p>\n<p>reducers\/sel_board.js<\/p>\n<p>[bash]<br \/>\nconst sel_board = (state=-1, action)=> {<\/p>\n<p>  switch (action.type) {<br \/>\n    case &#8220;BOARD_SELECT&#8221;:<br \/>\n      return action.id<br \/>\n    default:<br \/>\n      return state<br \/>\n  }<\/p>\n<p>}<\/p>\n<p>export default sel_board<\/p>\n<p>[\/bash]<\/p>\n<p>\u3053\u308c\u3082\uff11\u3064 const(function\uff09\u3092\u5b9a\u7fa9\u3057\u305f\u3082\u306e\u3002function\u306e\u5f15\u6570\u306e\uff11\u3064\u3081\u306f state\u3001\uff12\u3064\u3081\u304c action\u3002<br \/>\n\u3053\u308c\u306f\u307b\u307c\u56fa\u5b9a\u3067OK\u3002\u3067\u3001state\u306b\u306f \u521d\u671f\u5024\u3092\u30bb\u30c3\u30c8\u3057\u3066\u304a\u304f\u3002<br \/>\n\u63b2\u793a\u677f\u30a2\u30d7\u30ea\u3067\u306f\u8d77\u52d5\u76f4\u5f8c\u3001\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677f\u304c\u306a\u3044\u306e\u3067\u3001\u521d\u671f\u5024\u306f\u300c-1\u300d\u3002<br \/>\n\u3067\u3001function\u306e\u4e2d\u8eab\u306f\u3068\u3044\u3046\u3068\u3001 action.type\u306b\u30bb\u30c3\u30c8\u3055\u308c\u305f\u6587\u5b57\u5217\u304c\u3001\u81ea\u5206\u304c\u53cd\u5fdc\u3057\u305f\u3044\u30a4\u30d9\u30f3\u30c8\u304b\u5224\u65ad\u3057\u3066\u3001<br \/>\n\u3082\u3057\u305d\u3046\u3067\u3042\u308c\u3070\u3001\u30a4\u30d9\u30f3\u30c8\u5f8c\u306b\u5909\u66f4\u3057\u305f\u3044\u5024\u3092\u4f5c\u3063\u3066\u8fd4\u3059\u3068\u3044\u3046\u3082\u306e\u3002<br \/>\n\u4eca\u56de\u306f\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677f\u304c\u5909\u66f4\u3055\u308c\u305f\u3000\u3068\u3044\u3046\u30a4\u30d9\u30f3\u30c8\u304c\u6765\u308b\u306e\u3067\u3001\u5f53\u7136\u65b0\u3057\u304f\u9078\u3070\u308c\u305f\u63b2\u793a\u677f\u306eID\u3092\u8fd4\u3057\u3066\u3042\u3052\u308b<br \/>\n\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u3061\u3087\u3063\u3068\u96e3\u3057\u304f\u306a\u308a\u307e\u3059\u304c\u3001<br \/>\nreducer\u3067\u306f\u3001state\u306b\u5165\u3063\u3066\u3044\u308b\u73fe\u5728\u306e\u5024\u306f\u53c2\u7167\u3059\u308b\u306e\u307f\u3068\u3057\u3001\u65b0\u3057\u3044\u7d50\u679c\u3092 return\u3057\u3066\u3084\u308b\u306e\u304c\u304a\u7d04\u675f\u3067\u3059\u3002<\/p>\n<p>\u6b21\u306b\u753b\u9762\u3092\u69cb\u7bc9\u3059\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u63b2\u793a\u677f\u4e00\u89a7\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u300cBoardList\u300d\u306e\u4f8b\u3067\u3059\u3002<br \/>\n\u521d\u671f\u5316\u306e\u5f15\u6570\u306b\u3000{datas, selb, onBoardClick}\u3000\u304c\u6765\u3066\u3044\u307e\u3059\u3002<br \/>\ndatas\u3000\u306f\u63b2\u793a\u677f\u4e00\u89a7\u306e\u30c7\u30fc\u30bf\u306e\u914d\u5217\u3002<br \/>\nselb\u306f\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677f\u306eID\u3002<br \/>\nonBoardClick\u306f\u63b2\u793a\u677f\u3092\u9078\u629e\u3057\u305f\u6642\u306b\u53cd\u5fdc\u3057\u3066\u307b\u3057\u3044 function\u304c\u30bb\u30c3\u30c8\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30a4\u30d9\u30f3\u30c8\u306e\u51e6\u7406\u306f\u3053\u3053\u3067\u306f\u66f8\u304b\u306a\u3044\u306e\u304cRedux\u98a8\u3002<\/p>\n<p>components\/BoardList.js<br \/>\n[bash]<br \/>\nimport React from &#8220;react&#8221;<br \/>\nimport BoardLine from &#8220;.\/BoardLine&#8221;<\/p>\n<p>const BoardList = ({datas, selb, onBoardClick}) => {<br \/>\n  let list = []<\/p>\n<p>  datas.map((b) => {<br \/>\n    let active = (b.id == selb)<\/p>\n<p>    list.push(<BoardLine\n                key={b.id}\n                id={b.id}\n                title={b.title}\n                active={active}\n                onClick={() => onBoardClick(b.id)}<br \/>\n              \/>)<br \/>\n  })<\/p>\n<p>  return (<\/p>\n<div>\n      {list}\n    <\/div>\n<p>  )<br \/>\n}<\/p>\n<p>export default BoardList<\/p>\n<p>[\/bash]<\/p>\n<p>\u3053\u3053\u304c\u4e00\u756a\u96e3\u3057\u3044\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30e9\u30c3\u30d1\u30fc(container\uff09\u30af\u30e9\u30b9\u3002<br \/>\nBoardList.js\u3000\u3092\u30e9\u30c3\u30d7\u3059\u308b CBoardList.js<\/p>\n<p>containers\/CBoardList.js<br \/>\n[bash]<br \/>\nimport React from &#8220;react&#8221;<br \/>\nimport {connect} from &#8220;react-redux&#8221;<br \/>\nimport {board_select, comment_read} from &#8220;..\/actions\/index&#8221;<br \/>\nimport BoardList from &#8220;..\/components\/BoardList&#8221;<\/p>\n<p>const mapStateToProps = (state, ownProps) =>{<br \/>\n  return {<br \/>\n    datas: ownProps.boards,<br \/>\n    selb: state.sel_board<br \/>\n  }<br \/>\n}<\/p>\n<p>const mapDispatchToProps = (dispatch) => {<br \/>\n  return {<br \/>\n    onBoardClick: (id) => {<br \/>\n      dispatch(board_select(id))<\/p>\n<p>      $.ajax({<br \/>\n         type: &#8220;GET&#8221;,<br \/>\n         url: &#8220;\/board\/readComments\/&#8221; + id,<br \/>\n         async: false,<br \/>\n         dataType: &#8220;json&#8221;,<br \/>\n         data: &#8220;name=John&#038;location=Boston&#8221;,<br \/>\n         success: function(data, dataType){<br \/>\n           if (data.status == true){<br \/>\n             \/\/alert(data.rows.length);<br \/>\n             if (data.rows.length > 0){<br \/>\n               dispatch(comment_read(data.rows))<br \/>\n             }<br \/>\n             else{<br \/>\n               dispatch(comment_read([]))<br \/>\n             }<br \/>\n           }<br \/>\n         },<br \/>\n         error :function(XMLHttpRequest, textStatus, errorThrown){<br \/>\n         }<br \/>\n      });<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>const CBoardList = connect(mapStateToProps,mapDispatchToProps)(BoardList)<\/p>\n<p>export default CBoardList<\/p>\n<p>[\/bash]<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u3001\u4ee5\u4e0b\u306e\uff13\u3064\u3092\u304a\u3055\u3048\u308c\u3070\u3088\u3044\u3002<\/p>\n<p>const mapStateToProps = (state, ownProps) =>{<br \/>\nconst mapDispatchToProps = (dispatch) => {<br \/>\nconst \u30e9\u30c3\u30d1\u30fc\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8 = connect(mapStateToProps,mapDispatchToProps)(\u753b\u9762\u3092\u69cb\u7bc9\u3059\u308b\u5b9f\u614b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8)<\/p>\n<p>\uff11\u3064\uff11\u3064\u8aac\u660e\u3057\u3066\u3044\u304f\u3068\u3002<br \/>\nmapStateToProps\u3000\u3067\u306f\u3001store\u306estate\u304c\u76f4\u63a5\u53c2\u7167\u3067\u304d\u308b\u306e\u3067\u3001\u5b9f\u614b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30bb\u30c3\u30c8\u3057\u3066\u3042\u3052\u305f\u3044<br \/>\n\u5024\u3092\u3053\u3053\u3067\u30bb\u30c3\u30c8\u3059\u308b\u3002<br \/>\nmapDispatchToProps\u3000\u306f\u5b9f\u614b\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u767a\u751f\u3057\u305f\u30a4\u30d9\u30f3\u30c8\u306e\u51e6\u7406\u3092\u8a18\u8ff0\u3059\u308b\u3068\u3053\u308d\u3002<br \/>\nAjax\u7b49\u3067\u4f55\u3089\u304b\u30c7\u30fc\u30bf\u3092\u53d6\u3063\u3066\u304f\u308b\u306a\u308a\u3057\u3066\u3001\u64ae\u3063\u3066\u304d\u305f\u7d50\u679c\u3092\u5f15\u6570\u306b\u3057\u3066\u3001<br \/>\ndispatch(\u30a4\u30d9\u30f3\u30c8\u540d(\u30c7\u30fc\u30bf)) \u3068\u3057\u3066\u3084\u308b\u3002<\/p>\n<p>\u3053\u306e\u4f8b\u3067\u306f<\/p>\n<p>dispatch(comment_read(data.rows))<\/p>\n<p>\u3053\u3053\u3067\u4f55\u304c\u8d77\u3053\u3063\u3066\u3044\u308b\u304b\u3068\u3044\u3046\u3068\u3001comment_read\u3000\u3068\u3044\u3046 ActionCreator\u3092\u5909\u5316\u3059\u308b\u5024\u3092\u5f15\u6570\u306b\u3057\u3066\u547c\u3073\u51fa\u3059\u3002<br \/>\n\u547c\u3073\u3060\u3055\u308c\u305fActionCreator\u306f\u3001\u5f15\u6570\u3067\u6e21\u3063\u3066\u304d\u305f\u5024\u3092\u4f7f\u3063\u3066\u3001store\u306b\u65b0\u3057\u3044\u5024\u3092\u8fd4\u3059\u3002<\/p>\n<p>\u3059\u308b\u3068store\u306b\u30bb\u30c3\u30c8\u3055\u308c\u305f\u5024\u304c\u5909\u308f\u308b\u306e\u3067\u3001React\u304c\u81ea\u52d5\u7684\u306b\u305d\u306e\u5024\u3092\u4f7f\u3063\u3066\u3044\u308b\u90e8\u5206\u3092\u518d\u63cf\u753b\u3057\u3066\u304f\u308c\u308b\u3002<br \/>\n\u3068\u3044\u3046\u3082\u306e\u3002<\/p>\n<p>\u57fa\u672c\u306f\u3053\u308c\u3060\u3051\u3002\u3053\u308c\u3092\u7e70\u308a\u8fd4\u3057\u3066\u3044\u3051\u3070\u3001\u30a2\u30d7\u30ea\u304c\u7d44\u3081\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u306a\u3093\u304b\u3088\u304f\u308f\u304b\u3089\u3093\u306a\u3041\u3068\u3001\u6700\u521d\u306f\u3082\u3084\u3082\u3084\u3059\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u6163\u308c\u3066\u304f\u308c\u3070\u3001\u624b\u306b\u53d6\u308b\u3088\u3046\u306b\u5206\u304b\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001<br \/>\n\u9811\u5f35\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>GitHub\u306b\u30bd\u30fc\u30b9\u516c\u958b\u3057\u3066\u307e\u3059\u3002<\/h3>\n<p>\u3054\u81ea\u7531\u306b\u3054\u5229\u7528\u304f\u3060\u3055\u3044\u3002<br \/>\n<a href=\"https:\/\/github.com\/h-mito\/rails_redux_board\">https:\/\/github.com\/h-mito\/rails_redux_board<\/a><\/p>\n<p>\u304a\u308f\u308a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b \u3053\u30533\u9031\u9593\u307b\u3069\u6b7b\u306c\u307b\u3069React\u3068Redux\u3084\u3063\u3066\u3001\u3042\u308c\u3053\u308c\u5206\u304b\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u3053\u308c\u304b\u3089React+Redux\u3067\u958b\u767a\u3092\u59cb\u3081\u305f\u3044\u4eba\u5411\u3051\u306b\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u307f\u307e\u3059\u3002 \u516c\u5f0f\u30b5\u30a4\u30c8\u306e\u82f1\u8a9e\u8a18\u4e8b\u3084\u3001\u305d\u308c\u3092\u7ffb\u8a33\u3057\u3066\u304f\u308c\u3066\u3044\u308b\u3088\u3046\u306a\u30b5\u30a4\u30c8\u3092\u898b\u3066\u3082\u305d\u308c\u306a\u308a\u306b\u5206\u304b\u308b\u306e\u3067\u3059\u304c\u30fb\u30fb\u30fb \u306a\u3093\u3060\u304b\u3093\u3060\u8a00\u3063\u3066\u96e3\u3057\u3044\u3002 React\u306e\u7406\u89e3\u306f\u306a\u3093\u3068\u304b\u51fa\u6765\u3066\u3082\u3001Redux\u304c\u7279\u306b\u96e3\u3057\u3044\u3002 \u6b32\u5f35\u308a\u306a\u3093\u3067\u3059\u304c\u3001\u3068\u306b\u304b\u304f\u4e21\u65b9\u3092\u30b5\u30fc\u30c3\u3068\u7406\u89e3\u3057\u3066\u3001\u3055\u3063\u3055\u3068\u30a2\u30d7\u30ea\u7d44\u307f\u305f\u3044\u3088\u3068\u3044\u3046\u65b9\u306e\u52a9\u3051\u306b\u306a\u308c\u308c\u3070\u3068\u30fb\u30fb\u30fb \u8003\u3048\u3066\u3044\u304f\u624b\u9806 \u753b\u9762\u30a4\u30e1\u30fc\u30b8 \u753b\u9762\u3092\u69cb\u7bc9\u3059\u308b\u305f\u3081\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u968e\u5c64\u56f3 \u30b9\u30c6\u30fc\u30c8 \u30a4\u30d9\u30f3\u30c8 \u57fa\u672c\u7684\u306b\u3053\u306e\uff14\u3064\u3092\u8003\u3048\u308c\u3070OK\u3067\u3059\u3002 \u65e2\u306b\u5225\u306e\u8a18\u4e8b\u3067\u66f8\u3044\u3066\u3044\u308b\u3000Rails\u3068React\u3068Redux\u3092\u7d44\u307f\u5408\u308f\u305b\u305f\u63b2\u793a\u677f\u30a2\u30d7\u30ea\u306e\u753b\u9762\u3092\u4f8b\u306b\u3068\u3063\u3066\u8aac\u660e\u3057\u307e\u3059\u3002 \u307e\u305a\u306f\u4f5c\u308b\u30a2\u30d7\u30ea\u306e\u753b\u9762\u30a4\u30e1\u30fc\u30b8\u3092\u982d\u306e\u4e2d\u3067\u69cb\u7bc9\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u7d19\u306b\u7d75\u3092\u66f8\u3044\u3066\u307f\u305f\u308a\u3059\u308b\u3068\u3044\u3044\u3067\u3059\u306d\u3002 \u3053\u306e\u4f8b\u306e\u5834\u5408\u306f\u3001\u753b\u9762\u306f\u81f3\u3063\u3066\u30b7\u30f3\u30d7\u30eb\u3002\u753b\u9762\u5de6\u5074\u306b\u63b2\u793a\u677f\u4e00\u89a7\u304c\u30ea\u30b9\u30c8\u30a2\u30c3\u30d7\u3055\u308c\u3066\u3044\u3066\u3001\u305d\u306e\u63b2\u793a\u677f\u306e\u3069\u308c\u304b\u3092\u9078\u629e\u3059\u308b\u3068\u3001\u753b\u9762\u53f3\u5074\u306b\u63b2\u793a\u677f\u306b\u6295\u7a3f\u3055\u308c\u305f\u30b3\u30e1\u30f3\u30c8\u4e00\u89a7\u304c\u5217\u6319\u3055\u308c\u308b\u3002 \u753b\u9762\u53f3\u4e0a\u3067\u306f\u3001\u63b2\u793a\u677f\u306b\u65b0\u305f\u306b\u30b3\u30e1\u30f3\u30c8\u3092\u6295\u7a3f\u3067\u304d\u308b\u3002\u3053\u3093\u306a\u3082\u306e\u3002 \u3053\u306e\u753b\u9762\u3092\u69cb\u6210\u3059\u308b\u30d1\u30fc\u30c4\u3092React\u98a8\u306b\u8003\u3048\u3066\u307f\u308b\u3068\u3001\u3056\u3063\u3068\u3053\u3093\u306a\u611f\u3058\u3002 \u3053\u308c\u304c\u300c\u753b\u9762\u3092\u69cb\u7bc9\u3059\u308b\u305f\u3081\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u968e\u5c64\u56f3\u300d\u3002 \u6b21\u3001\u30b9\u30c6\u30fc\u30c8\u3002 \u3053\u306e\u753b\u9762\u30a4\u30e1\u30fc\u30b8\u3092\u898b\u3066\u3001\u5909\u52d5\u3057\u305d\u3046\u306a\u3082\u306e\u3092\u8003\u3048\u308b\u3002 \u3056\u3063\u3068\u8003\u3048\u308b\u3068\u63b2\u793a\u677f\u4e00\u89a7\u3068\u3001\u30b3\u30e1\u30f3\u30c8\u4e00\u89a7\u3001\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677f\u3001\u30e6\u30fc\u30b6\u30fc\u4e00\u89a7\u3000\u3050\u3089\u3044\u3002 \u30e6\u30fc\u30b6\u30fc\u4e00\u89a7\u304c\u306a\u3093\u3067\u5fc5\u8981\u304b\u3068\u3044\u3046\u3068\u3001\u3053\u306e\u30a2\u30d7\u30ea\u3067\u306f\u8aac\u660e\u3092\u7c21\u5358\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u30ed\u30b0\u30a4\u30f3\u51e6\u7406\u306a\u3069\u8a2d\u3051\u305a\u306b\u3001\u6295\u7a3f\u3059\u308b\u969b\u306b\u300c\u81ea\u5206\u306f\u8ab0\u3005\u3067\u3059\u3088\u300d\u3068\u9078\u629e\u3057\u3066\u3001\u30b3\u30e1\u30f3\u30c8\u3092\u6295\u7a3f\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u3067\u3059\u3002 \u3067\u3001\u4e0a\u8a18\u306e\uff14\u3064\u304c\u672c\u5f53\u306b\u30b9\u30c6\u30fc\u30c8\u304b\u8003\u3048\u308b\u3002 \u3088\u304f\u8003\u3048\u3066\u307f\u308b\u3068\u3001\u63b2\u793a\u677f\u4e00\u89a7\u306f\u8ffd\u52a0\u3067\u304d\u308b\u6a5f\u80fd\u304c\u306a\u3044\u306e\u3067\u3001\u521d\u671f\u5024\u56fa\u5b9a\u306e\u307e\u307e\u3002\u30e6\u30fc\u30b6\u30fc\u4e00\u89a7\u3082\u521d\u671f\u5024\u56fa\u5b9a\u306e\u307e\u307e\u3002 \u3088\u3063\u3066\u3053\u306e\uff12\u3064\u306f\u30b9\u30c6\u30fc\u30c8\u3068\u306f\u8003\u3048\u306a\u3044\u3002 \u3058\u3083\u3042\u3001\u30b9\u30c6\u30fc\u30c8\u3068\u3057\u3066\u6b8b\u308b\u306e\u306f \u30b3\u30e1\u30f3\u30c8\u4e00\u89a7 \u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677f \u306e\uff12\u3064\u3060\u3051\u3002 \u6b21\u3001\u30a4\u30d9\u30f3\u30c8\u3002 \u3053\u308c\u306f\u3059\u3050\u89e3\u308b\u3068\u601d\u3044\u307e\u3059\u3002 \u63b2\u793a\u677f\u4e00\u89a7\u304b\u3089\u3069\u308c\u304b\u3092\u9078\u629e\u3059\u308b \u63b2\u793a\u677f\u306b\u30b3\u30e1\u30f3\u30c8\u3092\u6295\u7a3f\u3059\u308b \u3053\u306e\uff12\u3064\u3060\u3051\u3002 \u3069\u3046\u3084\u3063\u3066\u30a2\u30d7\u30ea\u3092\u7d44\u307f\u4e0a\u3052\u3066\u3044\u304f\u304b \u753b\u9762\u30a4\u30e1\u30fc\u30b8 \u753b\u9762\u3092\u69cb\u7bc9\u3059\u308b\u305f\u3081\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u968e\u5c64\u56f3 \u30b9\u30c6\u30fc\u30c8 \u30a4\u30d9\u30f3\u30c8 \u8003\u3048\u308b\u624b\u9806\u3067\u3053\u308c\u306f\u3067\u304d\u305f\u306e\u3067\u3001\u3069\u3053\u304b\u3089\u304b\u624b\u3092\u4ed8\u3051\u3066\u3044\u304d\u307e\u3059\u3002 \u753b\u9762\u304b\u3089\u5148\u306b\u4f5c\u308a\u305f\u304f\u306a\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u3042\u308c\u3053\u308c\u3084\u3084\u3053\u3057\u304f\u306a\u308b\u306e\u3067 \u30a2\u30d7\u30ea\u306e\u30c8\u30c3\u30d7\u306b\u306a\u308bApp.js\u3000\u3050\u3089\u3044\u3060\u3051\u4f5c\u3063\u3066\u3001\u305d\u3053\u306bHelloWorld\u3050\u3089\u3044\u3092\u51fa\u3059\u3060\u3051\u306b\u3057\u3066\u3001 \u5148\u306b\u30c7\u30fc\u30bf\u69cb\u9020\u3068\u30a4\u30d9\u30f3\u30c8\u306e\u90e8\u5206\u3092\u8003\u3048\u307e\u3057\u3087\u3046\u3002\u305f\u3076\u3093\u3053\u308c\u304cRedux\u98a8\u306a\u8003\u3048\u65b9\u3002 \u30c7\u30fc\u30bf\u69cb\u9020\u3068\u306f\u3064\u307e\u308a\u30b9\u30c6\u30fc\u30c8\u306e\u3053\u3068\u3002\u30c7\u30fc\u30bf\u69cb\u9020\u304c\u5909\u5316\u3059\u308b\u3068\u304d\u306f\u3069\u3093\u306a\u6642\u304b\u3068\u3044\u3046\u3068\u30a4\u30d9\u30f3\u30c8\u304c\u767a\u751f\u3057\u305f\u6642\u3002 \u3068\u306a\u308b\u306e\u3067\u3001\u307e\u305a\u30a4\u30d9\u30f3\u30c8\u4e00\u89a7\uff08ActionCreator\uff09\u3092\u4f5c\u308a\u307e\u3057\u3087\u3046\u3002 actions\/index.js [bash] export const board_select = (id) => { return { type: &#8220;BOARD_SELECT&#8221;, id: id } } export const comment_read = (comments) => { return { type: &#8220;COMMENT_READ&#8221;, comments: comments } } [\/bash] \u3053\u3053\u3067\u306f\uff12\u3064\u306efunction\u3092\u4f5c\u3063\u3066\u3001\u305d\u306econst(function)\u3092export \u3057\u3066\u307e\u3059\u3002 function\u306e\u623b\u308a\u5024\u304c action\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3002 \u3061\u3087\u3063\u3068\u96e3\u3057\u304f\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u306d\u3002\u3068\u308a\u3042\u3048\u305a\u3001action\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u306fType\u30d7\u30ed\u30d1\u30c6\u30a3\u3092 \u5fc5\u305a\u4f5c\u308a\u3001\u305d\u3053\u306b\u3069\u3093\u306a\u30a4\u30d9\u30f3\u30c8\u304b\u8b58\u5225\u3067\u304d\u308b\u6587\u5b57\u5217\u3092\u30bb\u30c3\u30c8\u3057\u3066\u304a\u304d\u307e\u3059\u3002 \u305d\u3057\u3066\u3001type\u4ee5\u5916\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u30a4\u30d9\u30f3\u30c8\u3067\u767a\u751f\u3057\u305f\u3042\u3068\u306b\u5909\u5316\u3059\u308b\u5024\u3092\u5217\u6319\u3057\u307e\u3059\u3002 BOARD_SELECT \u3064\u307e\u308a\u3001\u63b2\u793a\u677f\u304c\u9078\u629e\u3055\u308c\u305f\u3089\u3001\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677fID\u304c\u5909\u308f\u308b\u306e\u3067\u3001 id\u3000\u3092\u30bb\u30c3\u30c8\u3057\u3066\u304a\u304f\u3068\u3044\u3046\u3088\u3046\u306a\u611f\u3058\u3002 \u6b21\u3001\u30a4\u30d9\u30f3\u30c8\u304c\u767a\u751f\u3057\u305f\u3042\u3068\u3001\u5b9f\u969b\u306b\u30c7\u30fc\u30bf(public\u5909\u6570\u307f\u305f\u3044\u306a\u30a4\u30e1\u30fc\u30b8\uff09\u3092\u5909\u66f4\u3059\u308b\u3068\u3053\u308d\u3092\u4f5c\u308a\u307e\u3059\u3002 \u305d\u306e\u5834\u6240\u304creducer\u3067\u3059\u3002 reducers\/sel_board.js [bash] const sel_board = (state=-1, action)=> { switch (action.type) { case &#8220;BOARD_SELECT&#8221;: return action.id default: return state } } export default sel_board [\/bash] \u3053\u308c\u3082\uff11\u3064 const(function\uff09\u3092\u5b9a\u7fa9\u3057\u305f\u3082\u306e\u3002function\u306e\u5f15\u6570\u306e\uff11\u3064\u3081\u306f state\u3001\uff12\u3064\u3081\u304c action\u3002 \u3053\u308c\u306f\u307b\u307c\u56fa\u5b9a\u3067OK\u3002\u3067\u3001state\u306b\u306f \u521d\u671f\u5024\u3092\u30bb\u30c3\u30c8\u3057\u3066\u304a\u304f\u3002 \u63b2\u793a\u677f\u30a2\u30d7\u30ea\u3067\u306f\u8d77\u52d5\u76f4\u5f8c\u3001\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677f\u304c\u306a\u3044\u306e\u3067\u3001\u521d\u671f\u5024\u306f\u300c-1\u300d\u3002 \u3067\u3001function\u306e\u4e2d\u8eab\u306f\u3068\u3044\u3046\u3068\u3001 action.type\u306b\u30bb\u30c3\u30c8\u3055\u308c\u305f\u6587\u5b57\u5217\u304c\u3001\u81ea\u5206\u304c\u53cd\u5fdc\u3057\u305f\u3044\u30a4\u30d9\u30f3\u30c8\u304b\u5224\u65ad\u3057\u3066\u3001 \u3082\u3057\u305d\u3046\u3067\u3042\u308c\u3070\u3001\u30a4\u30d9\u30f3\u30c8\u5f8c\u306b\u5909\u66f4\u3057\u305f\u3044\u5024\u3092\u4f5c\u3063\u3066\u8fd4\u3059\u3068\u3044\u3046\u3082\u306e\u3002 \u4eca\u56de\u306f\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677f\u304c\u5909\u66f4\u3055\u308c\u305f\u3000\u3068\u3044\u3046\u30a4\u30d9\u30f3\u30c8\u304c\u6765\u308b\u306e\u3067\u3001\u5f53\u7136\u65b0\u3057\u304f\u9078\u3070\u308c\u305f\u63b2\u793a\u677f\u306eID\u3092\u8fd4\u3057\u3066\u3042\u3052\u308b \u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002 \u3061\u3087\u3063\u3068\u96e3\u3057\u304f\u306a\u308a\u307e\u3059\u304c\u3001 reducer\u3067\u306f\u3001state\u306b\u5165\u3063\u3066\u3044\u308b\u73fe\u5728\u306e\u5024\u306f\u53c2\u7167\u3059\u308b\u306e\u307f\u3068\u3057\u3001\u65b0\u3057\u3044\u7d50\u679c\u3092 return\u3057\u3066\u3084\u308b\u306e\u304c\u304a\u7d04\u675f\u3067\u3059\u3002 \u6b21\u306b\u753b\u9762\u3092\u69cb\u7bc9\u3059\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002 \u63b2\u793a\u677f\u4e00\u89a7\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u300cBoardList\u300d\u306e\u4f8b\u3067\u3059\u3002 \u521d\u671f\u5316\u306e\u5f15\u6570\u306b\u3000{datas, selb, onBoardClick}\u3000\u304c\u6765\u3066\u3044\u307e\u3059\u3002 datas\u3000\u306f\u63b2\u793a\u677f\u4e00\u89a7\u306e\u30c7\u30fc\u30bf\u306e\u914d\u5217\u3002 selb\u306f\u30a2\u30af\u30c6\u30a3\u30d6\u306a\u63b2\u793a\u677f\u306eID\u3002 onBoardClick\u306f\u63b2\u793a\u677f\u3092\u9078\u629e\u3057\u305f\u6642\u306b\u53cd\u5fdc\u3057\u3066\u307b\u3057\u3044 function\u304c\u30bb\u30c3\u30c8\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u30a4\u30d9\u30f3\u30c8\u306e\u51e6\u7406\u306f\u3053\u3053\u3067\u306f\u66f8\u304b\u306a\u3044\u306e\u304cRedux\u98a8\u3002 components\/BoardList.js [bash] import React from &#8220;react&#8221; import BoardLine from &#8220;.\/BoardLine&#8221; const BoardList = ({datas, selb, onBoardClick}) => { let list = [] datas.map((b) => { let active = (b.id == selb) list.push( onBoardClick(b.id)} \/>) }) return ( {list} ) } export default BoardList [\/bash] \u3053\u3053\u304c\u4e00\u756a\u96e3\u3057\u3044\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30e9\u30c3\u30d1\u30fc(container\uff09\u30af\u30e9\u30b9\u3002 BoardList.js\u3000\u3092\u30e9\u30c3\u30d7\u3059\u308b CBoardList.js containers\/CBoardList.js [bash] import React from &#8220;react&#8221; import {connect} from &#8220;react-redux&#8221; import {board_select, comment_read} from &#8220;..\/actions\/index&#8221; import BoardList from &#8220;..\/components\/BoardList&#8221; const mapStateToProps = (state, ownProps) =>{ return { datas: ownProps.boards, selb: state.sel_board } } const mapDispatchToProps = (dispatch) => { return { onBoardClick: (id) => { dispatch(board_select(id)) $.ajax({ type: &#8220;GET&#8221;, url: &#8220;\/board\/readComments\/&#8221; + id, async: false, dataType: &#8220;json&#8221;, data: &#8220;name=John&#038;location=Boston&#8221;, success: function(data, dataType){ if (data.status == true){ \/\/alert(data.rows.length); if (data.rows.length > 0){ dispatch(comment_read(data.rows)) } else{ dispatch(comment_read([])) } } }, error :function(XMLHttpRequest, textStatus, errorThrown){ } }); } } } const CBoardList = connect(mapStateToProps,mapDispatchToProps)(BoardList) export default CBoardList [\/bash] \u3068\u308a\u3042\u3048\u305a\u3001\u4ee5\u4e0b\u306e\uff13\u3064\u3092\u304a\u3055\u3048\u308c\u3070\u3088\u3044\u3002 const mapStateToProps = (state, ownProps) =>{ const mapDispatchToProps = (dispatch) => { const \u30e9\u30c3\u30d1\u30fc\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8 = connect(mapStateToProps,mapDispatchToProps)(\u753b\u9762\u3092\u69cb\u7bc9\u3059\u308b\u5b9f\u614b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8) \uff11\u3064\uff11\u3064\u8aac\u660e\u3057\u3066\u3044\u304f\u3068\u3002 mapStateToProps\u3000\u3067\u306f\u3001store\u306estate\u304c\u76f4\u63a5\u53c2\u7167\u3067\u304d\u308b\u306e\u3067\u3001\u5b9f\u614b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30bb\u30c3\u30c8\u3057\u3066\u3042\u3052\u305f\u3044&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1525,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[77],"tags":[72,76],"class_list":{"0":"post-1559","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-react","8":"tag-reactjs","9":"tag-redux"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts\/1559","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1559"}],"version-history":[{"count":2,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts\/1559\/revisions"}],"predecessor-version":[{"id":1561,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/posts\/1559\/revisions\/1561"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=\/wp\/v2\/media\/1525"}],"wp:attachment":[{"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lovelinux.mydns.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}