{"id":13767,"date":"2021-07-23T09:18:05","date_gmt":"2021-07-23T00:18:05","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=13767"},"modified":"2023-05-27T22:07:12","modified_gmt":"2023-05-27T13:07:12","slug":"%e3%80%90react%e3%80%91%e3%80%8cpresentational-component%e3%80%8d%e3%81%a8%e3%80%8ccontainer-component%e3%80%8d","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=13767","title":{"rendered":"\u3010React\/Redux\u3011\u300cPresentational Component\u300d\u3068\u300cContainer Component\u300d\u3001\u300cHOC\u300d"},"content":{"rendered":"<p>\u4eca\u306fHooks\u304c\u4f7f\u3048\u308b\u6642\u4ee3\u306a\u306e\u3067\u3042\u307e\u308a\u3053\u306e\u8003\u3048\u65b9\u306f\u3057\u306a\u3044\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u3066\u3044\u307e\u3059\u304c\u3001\u904e\u53bb\u306e\u6848\u4ef6\u306e\u30bd\u30fc\u30b9\u3068\u304b\u3092\u8aad\u3080\u5834\u5408\u306b\u77e5\u3063\u3066\u304a\u304f\u3068\u826f\u3044\u6982\u5ff5\u304b\u3068\u601d\u3044\u307e\u3057\u305f\u306e\u3067\u3001\u307e\u3068\u3081\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>Redux\u3092\u4f7f\u3046\u306b\u3042\u305f\u3063\u3066\u3069\u306e\u3088\u3046\u306b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u5206\u3051\u308b\u304b\u306e\u601d\u60f3\u306e\u3053\u3068\u3067\u3059\u3002<\/p>\n<h2>Presentational Component<\/h2>\n<h3>\u7279\u5fb4<\/h3>\n<ul>\n<li>\u898b\u305f\u76ee\u306e\u8cac\u52d9\u3092\u62c5\u3046\u3002<\/li>\n<li>\u95a2\u6570\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u4f5c\u3089\u308c\u3066\u3044\u305f\u3002\uff08\u4eca\u307e\u3067\u306fHooks\u304c\u306a\u304b\u3063\u305f\u306e\u3067\u72b6\u614b\u3092\u6301\u3066\u306a\u304b\u3063\u305f\u305f\u3081\u3002\uff09<\/li>\n<li>Redux\u306eStore\u306b\u4f9d\u5b58\u3057\u306a\u3044\u3002<\/li>\n<li>DOM \u30de\u30fc\u30af\u30a2\u30c3\u30d7\u3084\u30b9\u30bf\u30a4\u30eb\u3092\u6301\u3064\u3002<\/li>\n<li>\u5b50\u8981\u7d20\u3068\u3057\u3066\u3001Presentational Component\u3001Container Component \u306e\u3069\u3061\u3089\u3082\u6301\u3061\u3046\u308b\u3002<\/li>\n<li>\u30c7\u30fc\u30bf\u3092\u81ea\u8eab\u3067\u52dd\u624b\u306b\u8aad\u307f\u8fbc\u3093\u3060\u308a\u3001\u6539\u5909\u3057\u306a\u3044\u3002<\/li>\n<li>\u30c7\u30fc\u30bf\u3084\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306f\u3001\u89aa\u304b\u3089 Props \u3068\u3057\u3066children\u3092\u53d7\u3051\u53d6\u308b\u3002(children\u3092\u30de\u30fc\u30af\u30a2\u30c3\u30d7\u306b\u57cb\u3081\u8fbc\u3080\u3060\u3051\u306b\u3059\u308b\u3002\uff09<\/li>\n<li>State \u3092\u6301\u3064\u3053\u3068\u306f\u5c11\u306a\u3044\uff08\u6301\u3063\u305f\u3068\u3057\u3066\u3082\u3001\u81ea\u8eab\u306e UI \u306b\u95a2\u3059\u308b\u72b6\u614b\u3060\u3051\uff09<\/li>\n<\/ul>\n<h2>Container Component<\/h2>\n<h3>\u7279\u5fb4<\/h3>\n<ul>\n<li>\u30a2\u30d7\u30ea\u306e\u52d5\u4f5c\u306e\u8cac\u52d9<\/li>\n<li>\u672c\u5f53\u306b\u30ed\u30b8\u30c3\u30af\u3060\u3051\u3092\u66f8\u304f\u3002<\/li>\n<li>Redux\u306eStore\u306b\u4f9d\u5b58\u3059\u308b\u3002<\/li>\n<li>\u5b50\u8981\u7d20\u3068\u3057\u3066\u3001Presentational Component\u3001Container Component \u306e\u3069\u3061\u3089\u3082\u6301\u3061\u3046\u308b\u3002<\/li>\n<li>DOM \u30de\u30fc\u30af\u30a2\u30c3\u30d7\u3084\u30b9\u30bf\u30a4\u30eb\u3092\u6301\u305f\u306a\u3044\u3002<\/li>\n<li>dispatch\u3067\u304d\u308b\u3002<\/li>\n<\/ul>\n<h2>\u4e8c\u3064\u306b\u5206\u3051\u308b\u30e1\u30ea\u30c3\u30c8<\/h2>\n<h3>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u90e8\u5206\u3068UI\u90e8\u5206\u306b\u5206\u96e2\u3067\u304d\u308b\u3002<\/h3>\n<p>\u898b\u305f\u76ee\u3092\u5909\u66f4\u3059\u308b\u304b\u3089\u3068\u8a00\u3063\u3066\u30ed\u30b8\u30c3\u30af\u3082\u5408\u308f\u305b\u3066\u5909\u66f4\u3059\u308b\u30d1\u30bf\u30fc\u30f3\u306f\u7a00\u306a\u306e\u3067\u4fdd\u5b88\u6027\u304c\u9ad8\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001Container Component\u306fPresentational Component\u306b\u52a0\u5de5\u3057\u305fprops\u3092\u6e21\u3059\u3060\u3051\u306a\u306e\u3067\u30ed\u30b8\u30c3\u30af\u306b\u5bfe\u3059\u308b\u30c6\u30b9\u30c8\u3082\u7c21\u5358\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u518d\u5229\u7528\u6027\u304c\u9ad8\u304f\u306a\u308b\u3002<\/h3>\n<h3>Container\u306b\u91cd\u8907\u3057\u305f\u30ec\u30a4\u30a2\u30a6\u30c8\u3092\u8a18\u8f09\u3057\u306a\u304f\u306a\u308b\u3002<\/h3>\n<h2>\u4e8c\u3064\u306b\u5206\u3051\u308b\u30c7\u30e1\u30ea\u30c3\u30c8<\/h2>\n<h3>\u3069\u306e\u7c92\u5ea6\u3067Container\u5c64\u3092\u5c0e\u5165\u3059\u308b\u306e\u304b\u5224\u65ad\u3059\u308b\u306e\u304c\u96e3\u3057\u3044\u3002<\/h3>\n<p>\u5927\u62b5\u306f\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092Container\u306b\u3057\u3066\u5b50\u3084\u5b6b\u306bprops\u3092\u30d0\u30b1\u30c4\u30ea\u30ec\u30fc\u3057\u3066\u3044\u304f\u5f62\u304c\u63a1\u7528\u3055\u308c\u308b\u3002\u305d\u308c\u3060\u3068\u30b3\u30fc\u30c9\u306e\u898b\u901a\u3057\u304c\u304b\u306a\u308a\u60aa\u304f\u306a\u308b\u3002\u89aa\u3068\u5b6b\u306e\u9593\u306b\u3082Container\u3068\u304b\u3092\u7528\u610f\u3059\u308c\u3070\u307e\u3060\u898b\u901a\u3057\u306f\u30de\u30b7\u306b\u306a\u308b\u304c\u3001\u305d\u308c\u3060\u3068\u4eca\u5ea6\u306fContainer\u306e\u6570\u304c\u5897\u3048\u3059\u304e\u308b\u554f\u984c\u304c\u767a\u751f\u3059\u308b\u3002Hooks\u3067\u767b\u5834\u3057\u305f<\/p>\n<h2>\u6628\u4eca\u3067\u306f<\/h2>\n<p>2019\u5e74\u306bHooks\u304c\u767b\u5834\u3057\u3066\u300cuseSelector\u300d\u3084\u300cuseDispatch\u300d\u3092\u4f7f\u3048\u3070Container\u306e\u7c92\u5ea6\u3092\u8003\u3048\u308b\u306e\u304c\u5927\u5909\u306a\u30c7\u30e1\u30ea\u30c3\u30c8\u306b\u5bfe\u5fdc\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>HOC(Heigher-Order-Component)\u3068\u306f\uff1f<\/h2>\n<ul>\n<li>\u9ad8\u968e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8<\/li>\n<li>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u5f15\u6570\u306b\u3068\u308a\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u8fd4\u3059\u95a2\u6570<\/li>\n<li>react-redux\u306econnect\u95a2\u6570\u3084React.memo\u306fHOC\u3067\u3059\u3002<\/li>\n<li>React\u754c\u9688\u3067\u4e00\u6642\u671f\u6d41\u884c\u3063\u305f\u304c\u3001hooks\u306e\u767b\u5834\u3067\u4e0b\u706b\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/li>\n<\/ul>\n<h3>\u4f7f\u3044\u6240<\/h3>\n<p>\u3042\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u3088\u304f\u4f7f\u3046\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u305f\u3044\u5834\u5408\u306b\u4f7f\u3044\u307e\u3059\u3002\uff08\u5225\u306e\u8a00\u8a9e\u3068\u304b\u3067\u3042\u308c\u3070\u3001\u300c\u30c7\u30b3\u30ec\u30fc\u30bf\u300d\u3068\u304b\u304c\u8a72\u5f53\u3059\u308b\u6587\u6cd5\u306b\u306a\u308a\u305d\u3046\u3067\u3059\u3002\uff09<\/p>\n<h4>\u4f8b<\/h4>\n<p>\u30e6\u30fc\u30b6\u30fc\u304c\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u308b\u5834\u5408\u306e\u307f\u3042\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u4ed8\u3051\u8db3\u3059\u3002<\/p>\n<h3>redux\u306econnect\u95a2\u6570<\/h3>\n<p>react-redux\u306econnect\u95a2\u6570\u306fHOC\u3067\u3059\u3002mapStateToProps\u3068actions\u3092\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306ethis.props\u306b\u6e21\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>React.memo<\/h3>\n<p>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u5f15\u6570\u3068\u3057\u3066\u3068\u308a\u65b0\u3057\u3044\u30e9\u30c3\u30d1\u30fc\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<h3>\u30e1\u30ea\u30c3\u30c8<\/h3>\n<ul>\n<li>\u30ed\u30b8\u30c3\u30af\u3092\u304d\u308c\u3044\u306b\u5206\u96e2\u3067\u304d\u308b\u3002<\/li>\n<li>1\u95a2\u65701\u5f79\u5272\u306b\u3057\u3084\u3059\u3044\u3002<\/li>\n<\/ul>\n<h3>\u30c7\u30e1\u30ea\u30c3\u30c8<\/h3>\n<ul>\n<li>HOC\u304b\u3089\u6e21\u3055\u308c\u308bprops\u540d\u304c\u91cd\u8907\u3059\u308b\u3068\u4f7f\u3048\u306a\u3044\u3002<\/li>\n<li>\u30e9\u30c3\u30d7\u3055\u308c\u308b\u5074\u304b\u3089\u898b\u3066\u3001\u89aa\u304b\u3089\u6e21\u3059props\u304bHOC\u304b\u3089\u304f\u308bprops\u304b\u5224\u65ad\u3067\u304d\u306a\u3044\u3002<\/li>\n<\/ul>\n<h3>\u5b9f\u88c5\u65b9\u6cd5<\/h3>\n<ol>\n<li>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u3088\u304f\u4f7f\u3046\u30ed\u30b8\u30c3\u30af\u3092\u66f8\u304d\u51fa\u3057\u3066HOC\u3068\u3057\u3066\u5916\u3060\u3057\u3059\u308b\u3002<\/li>\n<li>props\u3068config\u3068behavior\u306e\u5168\u3066\u3092child component\u306b\u6e21\u305b\u308b\u3088\u3046\u306b\u3059\u308b\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"\u4eca\u306fHooks\u304c\u4f7f\u3048\u308b\u6642\u4ee3\u306a\u306e\u3067\u3042\u307e\u308a\u3053\u306e\u8003\u3048\u65b9\u306f\u3057\u306a\u3044\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u3066\u3044\u307e\u3059\u304c\u3001\u904e\u53bb\u306e\u6848\u4ef6\u306e\u30bd\u30fc\u30b9\u3068\u304b\u3092\u8aad\u3080\u5834\u5408\u306b\u77e5\u3063\u3066\u304a\u304f\u3068\u826f\u3044\u6982\u5ff5\u304b\u3068\u601d\u3044\u307e\u3057\u305f\u306e\u3067\u3001\u307e\u3068\u3081\u3066\u304a\u304d\u307e\u3059\u3002 Redux\u3092\u4f7f\u3046\u306b\u3042\u305f\u3063\u3066\u3069\u306e\u3088\u3046\u306b\u30b3\u30f3\u30dd\u30fc [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[116,117],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13767"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13767"}],"version-history":[{"count":6,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13767\/revisions"}],"predecessor-version":[{"id":20418,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13767\/revisions\/20418"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13767"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}