{"id":8128,"date":"2017-06-20T11:16:59","date_gmt":"2017-06-20T08:16:59","guid":{"rendered":"http:\/\/railsware.com\/blog\/?p=8128"},"modified":"2021-08-12T16:58:06","modified_gmt":"2021-08-12T13:58:06","slug":"hideable-react-component-using-hoc","status":"publish","type":"post","link":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/","title":{"rendered":"Hideable React component using HOC"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Imagine that we have a very simple <code class=\"\" data-line=\"\">React<\/code> component <code class=\"\" data-line=\"\">Hello<\/code> which greets a user with a message:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:javascript\">import React from 'react';\nimport PropTypes from 'prop-types';\n\nexport default function Hello({ name }) {\n  return (<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Hello, {name}!<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:javascript\">  );\n}\nHello.propTypes = {\n  name: PropTypes.string.isRequired\n};\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And here is how we use it:<\/p>\n\n\n\n<div>&nbsp;<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Great simple component, we really like the code. But it turns out that the <code class=\"\" data-line=\"\">name<\/code> value can be <code class=\"\" data-line=\"\">null<\/code> until we fetch it from a Back-End. We don&#8217;t want our users to see a stub: <span class=\"lang:javascript crayon-inline\">Hello, !<\/span>. So we decided to hide the text if the <code class=\"\" data-line=\"\">name<\/code> is <code class=\"\" data-line=\"\">null<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:javascript\">import React from 'react';\nimport PropTypes from 'prop-types';\n\nexport default function Hello({ name }) {\n  if (name == null) {\n    return null;\n  }\n  return (<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Hello, {name}!<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:javascript\">  );\n}\nHello.propTypes = {\n  name: PropTypes.string.isRequired\n};\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Looks good! Stub has gone and the message shows up only when the profile is loaded. But there is another issue &#8211; some noisy error message in the console:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted toolbar:2 wrap:true nums:false\">Warning: Failed prop type: Required prop 'name' was not specified in 'Hello'\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ouch, because <code class=\"\" data-line=\"\">name<\/code> is <code class=\"\" data-line=\"\">null<\/code> it doesn&#8217;t pass <code class=\"\" data-line=\"\">propTypes<\/code> validation. Maybe we need to provide some default value like empty string and check for the name not to be empty?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This escalates quickly and we are now shedding crutches instead of focusing on the business logic of the component. What if we have dozens of required properties &#8211; name, age and other data which will come later. It doesn&#8217;t sound cool if we have to set up some default values for all of them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Of course, this case can be handled directly by JavaScript outside of the component:<\/p>\n\n\n\n<div>{user.name &amp;&amp; }<\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This solution is okay but what if we use <code class=\"\" data-line=\"\">Redux<\/code> and provide <code class=\"\" data-line=\"\">name<\/code> value directly to container:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:javascript\">import { connect } from 'react-redux';\nimport Hello from '..\/..\/components\/Hello';\n\nconst mapStateToProps = (state) =&gt; {\n  const user = state.user;\n  return {\n    name: user.name\n  };\n};\n\nexport default connect(mapStateToProps)(Hello);\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we need to pass the <code class=\"\" data-line=\"\">user<\/code> object to the Hello&#8217;s parent for using JavaScript-hiding. Or we should rollback to the uglier solution and handle empty state within <code class=\"\" data-line=\"\">Hello<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Solution<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">But can we do better? Can we have a simple, original, neat version of <code class=\"\" data-line=\"\">Hello<\/code> with a normal <code class=\"\" data-line=\"\">propTypes<\/code> validation and make them hideable on some condition? As a bonus, we want to extract such behavior and reuse with other components.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s actually doable! Because React components are composable, we can easily create Higher Order Component(HOC) which accepts original always-shown component and turns it into hideable when some condition is met. Here is the code of such <code class=\"\" data-line=\"\">HOC<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:javascript\">import React from 'react';\nimport PropTypes from 'prop-types';\n\nconst propTypes = {\n  hideComponent: PropTypes.bool,\n  children: PropTypes.node\n};\nconst defaultProps = {\n  hideComponent: false\n};\n\nfunction getDisplayName(component) {\n  return component.displayName || component.name || 'Component';\n}\n\nexport default function Hideable(component) {\n  function HideableComponent({ hideComponent, children, ...props }) {\n    if (hideComponent) {\n      return null;\n    }\n    return React.createElement(component, props, children);\n  }\n  HideableComponent.displayName = `Hideable(${getDisplayName(component)})`;\n  HideableComponent.propTypes = propTypes;\n  HideableComponent.defaultProps = defaultProps;\n  return HideableComponent;\n}\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So <code class=\"\" data-line=\"\">Hideable<\/code> is a simple function which wraps any passed-in component into a proxy <code class=\"\" data-line=\"\">HideableComponent<\/code>. This proxy component has only one real property &#8211; <code class=\"\" data-line=\"\">hideComponent<\/code> and if the value of <code class=\"\" data-line=\"\">hideComponent<\/code> is truthy &#8211; child component will not be rendered:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/06\/Hideable-e1497452196938.png\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"321\" src=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/06\/Hideable-e1497452196938.png\" alt=\"Hideable component\" class=\"wp-image-8740\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s make our <code class=\"\" data-line=\"\">Hello<\/code> hideable and wrap it into <code class=\"\" data-line=\"\">Redux<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:javascript\">import { connect } from 'react-redux';\nimport Hello from '..\/..\/components\/Hello';\nimport Hideable from '..\/..\/utils\/hideable';\n\nconst HideableHello = Hideable(Hello);\n\nconst mapStateToProps = (state) =&gt; {\n  const user = state.user;\n  if (!user.name) {\n    return { hideComponent: true };\n  }\n  return {\n    name: user.name\n  };\n};\nexport default connect(mapStateToProps)(HideableHello);\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now <code class=\"\" data-line=\"\">mapStateToProps<\/code> manages visibility of the <code class=\"\" data-line=\"\">Hello<\/code> component and we haven&#8217;t changed anything within the original <code class=\"\" data-line=\"\">Hello<\/code> component.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">So we started from a very simple component and ended up with the same component topped-up with hideable logic. Using the same HOC approach, you can build more complex shareable behaviors and use them to build complex components from the simple ones.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it! I hope this neat trick will help you write simpler React components and reduce an amount of a boilerplate code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Imagine that we have a very simple React component Hello which greets a user with a message: import React from &#8216;react&#8217;; import PropTypes from &#8216;prop-types&#8217;; export default function Hello({ name }) { return ( Hello, {name}! ); } Hello.propTypes = { name: PropTypes.string.isRequired }; And here is how we use it: &nbsp; &nbsp; Great simple&#8230;<\/p>\n","protected":false},"author":25,"featured_media":9409,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[3],"tags":[],"coauthors":["Sergii Boiko"],"class_list":["post-8128","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"The Problem: Imagine that we have a very simple `React` component `Hello` which greets a user with a message...\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"Sergii Boiko\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"| Blog on Engineering, Product Management, Transparency, Culture and many more...\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Hideable React component using HOC | Railsware Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"The Problem: Imagine that we have a very simple `React` component `Hello` which greets a user with a message...\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/06\/Hideable-React.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/06\/Hideable-React.png\" \/>\n\t\t<meta property=\"og:image:width\" content=\"360\" \/>\n\t\t<meta property=\"og:image:height\" content=\"360\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2017-06-20T08:16:59+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2021-08-12T13:58:06+00:00\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#article\",\"name\":\"Hideable React component using HOC | Railsware Blog\",\"headline\":\"Hideable React component using HOC\",\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/06\\\/Hideable-React.png\",\"width\":360,\"height\":360,\"caption\":\"Hideable React component using HOC\"},\"datePublished\":\"2017-06-20T11:16:59+03:00\",\"dateModified\":\"2021-08-12T16:58:06+03:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#webpage\"},\"articleSection\":\"Engineering\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"position\":2,\"name\":\"Engineering\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#listItem\",\"name\":\"Hideable React component using HOC\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#listItem\",\"position\":3,\"name\":\"Hideable React component using HOC\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/Logo-circle.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#organizationLogo\",\"width\":3137,\"height\":1054,\"caption\":\"Railsware logo\"},\"image\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#organizationLogo\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/\",\"name\":\"Sergii Boiko\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#authorImage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/sergii-boiko-96x96.jpg\",\"width\":96,\"height\":96,\"caption\":\"Sergii Boiko\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#webpage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/\",\"name\":\"Hideable React component using HOC | Railsware Blog\",\"description\":\"The Problem: Imagine that we have a very simple `React` component `Hello` which greets a user with a message...\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/sergii-boiko\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/06\\\/Hideable-React.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#mainImage\",\"width\":360,\"height\":360,\"caption\":\"Hideable React component using HOC\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/hideable-react-component-using-hoc\\\/#mainImage\"},\"datePublished\":\"2017-06-20T11:16:59+03:00\",\"dateModified\":\"2021-08-12T16:58:06+03:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Hideable React component using HOC | Railsware Blog","description":"The Problem: Imagine that we have a very simple `React` component `Hello` which greets a user with a message...","canonical_url":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#article","name":"Hideable React component using HOC | Railsware Blog","headline":"Hideable React component using HOC","author":{"@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author"},"publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/06\/Hideable-React.png","width":360,"height":360,"caption":"Hideable React component using HOC"},"datePublished":"2017-06-20T11:16:59+03:00","dateModified":"2021-08-12T16:58:06+03:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#webpage"},"isPartOf":{"@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#webpage"},"articleSection":"Engineering"},{"@type":"BreadcrumbList","@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/railsware.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","position":2,"name":"Engineering","item":"https:\/\/railsware.com\/blog\/category\/development\/","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#listItem","name":"Hideable React component using HOC"},"previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#listItem","position":3,"name":"Hideable React component using HOC","previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}}]},{"@type":"Organization","@id":"https:\/\/railsware.com\/blog\/#organization","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","url":"https:\/\/railsware.com\/blog\/","logo":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2020\/11\/Logo-circle.png","@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#organizationLogo","width":3137,"height":1054,"caption":"Railsware logo"},"image":{"@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#organizationLogo"}},{"@type":"Person","@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author","url":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/","name":"Sergii Boiko","image":{"@type":"ImageObject","@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#authorImage","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2021\/06\/sergii-boiko-96x96.jpg","width":96,"height":96,"caption":"Sergii Boiko"}},{"@type":"WebPage","@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#webpage","url":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/","name":"Hideable React component using HOC | Railsware Blog","description":"The Problem: Imagine that we have a very simple `React` component `Hello` which greets a user with a message...","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/railsware.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#breadcrumblist"},"author":{"@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author"},"creator":{"@id":"https:\/\/railsware.com\/blog\/author\/sergii-boiko\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/06\/Hideable-React.png","@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#mainImage","width":360,"height":360,"caption":"Hideable React component using HOC"},"primaryImageOfPage":{"@id":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/#mainImage"},"datePublished":"2017-06-20T11:16:59+03:00","dateModified":"2021-08-12T16:58:06+03:00"},{"@type":"WebSite","@id":"https:\/\/railsware.com\/blog\/#website","url":"https:\/\/railsware.com\/blog\/","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","inLanguage":"en-US","publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"| Blog on Engineering, Product Management, Transparency, Culture and many more...","og:type":"article","og:title":"Hideable React component using HOC | Railsware Blog","og:description":"The Problem: Imagine that we have a very simple `React` component `Hello` which greets a user with a message...","og:url":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/","og:image":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/06\/Hideable-React.png","og:image:secure_url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/06\/Hideable-React.png","og:image:width":360,"og:image:height":360,"article:published_time":"2017-06-20T08:16:59+00:00","article:modified_time":"2021-08-12T13:58:06+00:00"},"aioseo_meta_data":{"post_id":"8128","title":null,"description":"The Problem: Imagine that we have a very simple `React` component `Hello` which greets a user with a message...","keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-6386167d25185","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":{"locations":{"business":{"name":"","businessType":"","image":"","areaServed":"","urls":{"website":"","aboutPage":"","contactPage":""},"address":{"streetLine1":"","streetLine2":"","zipCode":"","city":"","state":"","country":"","addressFormat":"#streetLineOne\n#streetLineTwo\n#city, #state #zipCode"},"contact":{"email":"","phone":"","phoneFormatted":"","fax":"","faxFormatted":""},"ids":{"vat":"","tax":"","chamberOfCommerce":""},"payment":{"priceRange":"","currenciesAccepted":"","methods":""}}},"openingHours":{"useDefaults":true,"show":true,"alwaysOpen":false,"use24hFormat":false,"timezone":"","labels":{"closed":"","alwaysOpen":""},"days":{"monday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"tuesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"wednesday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"thursday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"friday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"saturday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"},"sunday":{"open24h":false,"closed":false,"openTime":"09:00","closeTime":"17:00"}}}},"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-01-04 12:44:31","updated":"2025-09-26 11:24:39","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\/category\/development\/\" title=\"Engineering\">Engineering<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tHideable React component using HOC\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/railsware.com\/blog"},{"label":"Engineering","link":"https:\/\/railsware.com\/blog\/category\/development\/"},{"label":"Hideable React component using HOC","link":"https:\/\/railsware.com\/blog\/hideable-react-component-using-hoc\/"}],"categories_data":[{"name":"Engineering","link":"https:\/\/railsware.com\/blog?category=development"}],"post_thumbnails":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2017\/06\/Hideable-React.png","article_background":"","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/8128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/comments?post=8128"}],"version-history":[{"count":33,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/8128\/revisions"}],"predecessor-version":[{"id":13989,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/8128\/revisions\/13989"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media\/9409"}],"wp:attachment":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media?parent=8128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/categories?post=8128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/tags?post=8128"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/coauthors?post=8128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}