{"id":2442,"date":"2018-02-19T10:00:52","date_gmt":"2018-02-19T01:00:52","guid":{"rendered":"https:\/\/blog.timecrowd.net\/?p=2442"},"modified":"2018-02-09T17:33:30","modified_gmt":"2018-02-09T08:33:30","slug":"build-stateless-component-by-recompose","status":"publish","type":"post","link":"https:\/\/blog.timecrowd.net\/build-stateless-component-by-recompose\/","title":{"rendered":"recompose\u3092\u4f7f\u3063\u3066\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u30b9\u30c6\u30fc\u30c8\u30ec\u30b9\u306b\u3059\u308b"},"content":{"rendered":"<p>TimeCrowd\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u306f\u30d5\u30ebReact\u3067\u4f5c\u3089\u308c\u3066\u3044\u307e\u3059\u3002\u958b\u767a\u5f53\u521d\u306f\u53f3\u3082\u5de6\u3082\u308f\u304b\u3089\u305a\u30d3\u30b8\u30cd\u30b9\u30ed\u30b8\u30c3\u30af\u3084state\u3092\u5168\u3066\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u542b\u3081\u3066\u3057\u307e\u3063\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u305f\u3060React + Redux\u306e\u958b\u767a\u306b\u3082\u6163\u308c\u3001\u30b3\u30fc\u30c9\u306e\u898f\u6a21\u3082\u5927\u304d\u304f\u306a\u3063\u3066\u304d\u305f\u3068\u3053\u308d\u3067\u3001\u8272\u3005\u3068\u5f0a\u5bb3\u3082\u767a\u751f\u3057\u3066\u304d\u3066\u304a\u308a\u3001\u5168\u4f53\u7684\u306a\u8a2d\u8a08\u3092\u8003\u3048\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u8003\u3048\u59cb\u3081\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u3093\u306b\u3061\u306f\u3001\u53f0\u6e7e\u884c\u304d\u30921\u30f6\u6708\u5f8c\u306b\u63a7\u3048\u305f\u65c5\u3059\u308b\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u4e09\u5b85\u3067\u3059\u3002<\/p>\n<p>\u30c6\u30b9\u30bf\u30d6\u30eb\u306a\u69cb\u6210\u306b\u3059\u308b\u305f\u3081\u306b\u4eca\u56de\u306frecompose\u3092\u4f7f\u3063\u3066React\u306e\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u3068\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u5206\u96e2\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<div id=\"toc_container\" class=\"toc_white no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#recompose\"><span class=\"toc_number toc_depth_1\">1<\/span> recompose\u3068\u306f\uff1f<\/a><\/li><li><a href=\"#lifecycleReact\"><span class=\"toc_number toc_depth_1\">2<\/span> lifecycle\u3092\u4f7f\u3063\u3066React\u306e\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u3068\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3092\u5206\u96e2<\/a><\/li><li><a href=\"#recompose-2\"><span class=\"toc_number toc_depth_1\">3<\/span> recompose\u3092\u4f7f\u3046\u30e1\u30ea\u30c3\u30c8\u3068\u30c7\u30e1\u30ea\u30c3\u30c8<\/a><\/li><\/ul><\/div>\n<h2><span id=\"recompose\">recompose\u3068\u306f\uff1f<\/span><\/h2>\n<p>\u307e\u305a\u306frecompose\u3068\u306f\u3069\u3093\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u306a\u306e\u304b\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<blockquote><p>A React utility belt for function components and higher-order components.<\/p>\n<p><a href=\"https:\/\/github.com\/acdlite\/recompose\" target=\"_blank\" rel=\"noopener\">acdlite\/recompose: A React utility belt for function components and higher-order components.<\/a><\/p><\/blockquote>\n<p>function components\u3084higher-order components\u3092\u63d0\u4f9b\u3059\u308b\u305f\u3081\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>function components\u3068\u306fStateless functional components\u306e\u3053\u3068\u3067\u3057\u3087\u3046\u304b\u3002Stateless functional components\u306b\u3064\u3044\u3066\u306f\u3044\u304f\u3064\u304b\u7d39\u4ecb\u8a18\u4e8b\u304c\u3042\u308b\u306e\u3067\u53c2\u7167\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<ul>\n<li><a href=\"https:\/\/mae.chab.in\/archives\/2854\" target=\"_blank\" rel=\"noopener\">\u3010React\u3011\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u30b7\u30f3\u30d7\u30eb\u306b\u66f8\u304f\u305f\u3081\u306eStateless Functional Components\u306b\u3064\u3044\u3066 | maesblog<\/a><\/li>\n<li><a href=\"https:\/\/qiita.com\/inuscript\/items\/372727448b58d4738018\" target=\"_blank\" rel=\"noopener\">\u30e1\u30f3\u30c6\u30ca\u30d6\u30eb\u306a React Component \u3092\u76ee\u6307\u3059\u305f\u3081\u306e\u5c0f\u6280\u96c6 &#8211; Qiita<\/a><\/li>\n<li><a href=\"https:\/\/qiita.com\/kotaroito\/items\/e36ebac185b6b1d8538d\" target=\"_blank\" rel=\"noopener\">Stateless \u306a React Component \u306e\u8a18\u6cd5\u3092\u307e\u3068\u3081\u3066\u307f\u305f &#8211; Qiita<\/a><\/li>\n<\/ul>\n<p>Stateless functional components\u306f\u30b7\u30f3\u30d7\u30eb\u306aDOM\u3092\u8fd4\u3059\u95a2\u6570\u3068\u3044\u3063\u305f\u3068\u3053\u308d\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>higher-order components\u306b\u3064\u3044\u3066\u306f\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3092\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<ul>\n<li><a href=\"https:\/\/reactjs.org\/docs\/higher-order-components.html\" target=\"_blank\" rel=\"noopener\">Higher-Order Components &#8211; React<\/a><\/li>\n<li><a href=\"http:\/\/postd.cc\/react-higher-order-components-in-depth\/\" target=\"_blank\" rel=\"noopener\">React\u306eHigher Order Components\u8a73\u89e3 : \u5b9f\u88c5\u306e2\u3064\u306e\u30d1\u30bf\u30fc\u30f3\u3068\u3001\u89aaComponent\u3068\u306e\u6bd4\u8f03 | \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0 | POSTD<\/a><\/li>\n<\/ul>\n<blockquote><p>Concretely, <strong>a higher-order component is a function that takes a component and returns a new component.<\/strong><\/p>\n<p><a href=\"https:\/\/reactjs.org\/docs\/higher-order-components.html\" target=\"_blank\" rel=\"noopener\">Higher-Order Components &#8211; React<\/a><\/p><\/blockquote>\n<p>higher-order components\u3068\u306f\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u53d7\u3051\u53d6\u3063\u3066\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u8fd4\u3059\u95a2\u6570\u306e\u3053\u3068\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u982d\u6587\u5b57\u3092\u53d6\u3063\u3066HOC\u3068\u8a00\u3044\u307e\u3059\u304c\u3001\u4eca\u56de\u306f\u8a73\u7d30\u306b\u306f\u89e6\u308c\u307e\u305b\u3093\u3002<\/p>\n<h2><span id=\"lifecycleReact\">lifecycle\u3092\u4f7f\u3063\u3066React\u306e\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u3068\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3092\u5206\u96e2<\/span><\/h2>\n<p>recompose\u306eAPI\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u8aad\u3080\u3068\u305f\u304f\u3055\u3093\u306e\u95a2\u6570\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002\u4eca\u56de\u306f\u305d\u306e\u4e2d\u304b\u3089lifecycle\u3092\u4f7f\u3063\u3066React\u306e\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u3068Stateless functional components\u3092\u5206\u96e2\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u4e00\u822c\u7684\u306aReact\u306eComponent\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5f62\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><code>\/\/ Home.jsx\r\nimport React, { Component } from 'react';\r\n\r\nexport default class Home extends Component {\r\n  constructor(props) {\r\n    super(props);\r\n  }\r\n\r\n  componentDidMount() {\r\n    doSomething();\r\n  }\r\n\r\n  render() {\r\n    return (\r\n      &lt;div&gt;This is my home&lt;\/div&gt;\r\n    );\r\n  }\r\n}<\/code><\/pre>\n<p>\u4f55\u306e\u5909\u54f2\u3082\u306a\u3044\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u3059\u3002\u3053\u308c\u3092recompose\u3092\u4f7f\u3063\u3066\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u3092\u7ba1\u7406\u3059\u308b\u95a2\u6570\u3068Stateless functional components\u306b\u5206\u96e2\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<pre><code>\/\/ Home.jsx\r\nfunction Home(props) {\r\n  return (\r\n    &lt;div&gt;This is my home&lt;\/div&gt;\r\n  )\r\n}\r\n\r\n\/\/ HomeWithLifeCycle.js\r\nimport { lifecycle, } from 'recompose';\r\n\r\nconst HomeWithLifeCycle = lifecycle({\r\n  componentDidMount() {\r\n    doSomething();\r\n  },\r\n})(Home);\r\n\r\nexport default HomeWithLifeCycle;<\/code><\/pre>\n<p>\u3069\u3046\u3067\u3057\u3087\u3046\u3001Home.jsx\u306f\u30b7\u30f3\u30d7\u30eb\u306aDOM\u3092\u8fd4\u3059\u95a2\u6570\u3068\u306a\u308a\u3001HomeWithLifeCycle.js\u304cReact\u306e\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u3092\u7ba1\u7406\u3059\u308b\u5f79\u5272\u3092\u62c5\u3046\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u30ed\u30b8\u30c3\u30af\u3068\u63cf\u753b\u3092\u5206\u96e2\u3059\u308c\u3070\u3001\u30c7\u30b6\u30a4\u30ca\u30fc\u306bStateless functional components\u3092\u66f8\u3044\u3066\u3082\u3089\u3044\u3001\u30ed\u30b8\u30c3\u30af\u90e8\u5206\u306f\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30b8\u30cb\u30a2\u304c\u66f8\u304f\u3068\u3044\u3046\u5206\u696d\u3082\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2><span id=\"recompose-2\">recompose\u3092\u4f7f\u3046\u30e1\u30ea\u30c3\u30c8\u3068\u30c7\u30e1\u30ea\u30c3\u30c8<\/span><\/h2>\n<p>\u6700\u5f8c\u306brecompose\u3092\u4f7f\u3063\u3066\u51e6\u7406\u3092\u5206\u96e2\u3059\u308b\u30e1\u30ea\u30c3\u30c8\u3068\u30c7\u30e1\u30ea\u30c3\u30c8\u3092\u81ea\u5206\u306a\u308a\u306b\u307e\u3068\u3081\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h3>\u30e1\u30ea\u30c3\u30c8<\/h3>\n<ul>\n<li>\u95a2\u5fc3\u4e8b\u3092\u5206\u96e2\u3059\u308b\u3053\u3068\u3067\u3001\u8003\u3048\u306a\u3051\u308c\u3070\u3044\u3051\u306a\u3044\u3053\u3068\u304c\u6e1b\u308b<\/li>\n<li>\u4e00\u3064\u4e00\u3064\u306e\u51e6\u7406\u3092\u30b7\u30f3\u30d7\u30eb\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u30c6\u30b9\u30c8\u304c\u66f8\u304d\u3084\u3059\u304f\u306a\u308b<\/li>\n<li>Stateless functional components\u304c\u5897\u3048\u308c\u3070\u518d\u5229\u7528\u6027\u304c\u9ad8\u304f\u306a\u308b<\/li>\n<li>\u5358\u7d14\u306aDOM\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3042\u308c\u3070\u30c7\u30b6\u30a4\u30ca\u30fc\u306b\u76f4\u63a5\u4f5c\u3063\u3066\u3082\u3089\u3046\u3053\u3068\u3082\u53ef\u80fd<\/li>\n<\/ul>\n<h3>\u30c7\u30e1\u30ea\u30c3\u30c8<\/h3>\n<ul>\n<li>\u30eb\u30fc\u30eb\u3092\u6c7a\u3081\u3066\u6574\u7406\u3057\u3066\u30b3\u30fc\u30c9\u3092\u66f8\u304b\u306a\u3044\u3068\u3001\u95a2\u9023\u6027\u304c\u308f\u304b\u3089\u305a\u6df7\u4e71\u306e\u5143\u306b\u306a\u308b<\/li>\n<li>\u30d5\u30a1\u30a4\u30eb\u3092\u5206\u5272\u3059\u308b\u3053\u3068\u3067\u7ba1\u7406\u30b3\u30b9\u30c8\u304c\u5897\u5927\u3059\u308b<\/li>\n<\/ul>\n<p>\u307e\u3060\u307e\u3060\u4f7f\u3044\u59cb\u3081\u305f\u3070\u304b\u308a\u3067\u3059\u304c\u3001\u4f7f\u3044\u65b9\u306b\u3088\u3063\u3066\u306f\u95a2\u5fc3\u4e8b\u3092\u5206\u96e2\u3067\u304d\u3066\u3001\u3055\u3089\u306b\u30c6\u30b9\u30c8\u3082\u3057\u3084\u304f\u306a\u308b\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u304b\u3089\u30e6\u30fc\u30b6\u30fc\u306b\u5b89\u5b9a\u3057\u305f\u6a5f\u80fd\u3092\u7d20\u65e9\u304f\u63d0\u4f9b\u3057\u3066\u3044\u3051\u308b\u3088\u3046\u306b\u826f\u3044\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"TimeCrowd\u306e\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u306f\u30d5\u30ebReact\u3067\u4f5c\u3089\u308c\u3066\u3044\u307e\u3059\u3002\u958b\u767a\u5f53\u521d\u306f\u53f3\u3082\u5de6\u3082\u308f\u304b\u3089\u305a\u30d3\u30b8\u30cd\u30b9\u30ed\u30b8\u30c3\u30af\u3084state\u3092\u5168\u3066\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3&#8230;","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"cybocfi_hide_featured_image":""},"categories":[5],"tags":[36,38,12],"_links":{"self":[{"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/posts\/2442"}],"collection":[{"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/comments?post=2442"}],"version-history":[{"count":4,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/posts\/2442\/revisions"}],"predecessor-version":[{"id":2446,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/posts\/2442\/revisions\/2446"}],"wp:attachment":[{"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/media?parent=2442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/categories?post=2442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.timecrowd.net\/wp-json\/wp\/v2\/tags?post=2442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}