{"id":5346,"date":"2022-11-14T07:55:35","date_gmt":"2022-11-14T12:55:35","guid":{"rendered":"https:\/\/www.cloudsurph.com\/?p=5346"},"modified":"2022-11-14T07:55:52","modified_gmt":"2022-11-14T12:55:52","slug":"reactjs-how-to-use-conditional-rendering","status":"publish","type":"post","link":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/","title":{"rendered":"ReactJS: how to use Conditional Rendering"},"content":{"rendered":"<p>In this article, we can try to define ReactJS: how to use Conditional Rendering, react Conditional Rendering, and how can we use Conditional Rendering in react.<\/p>\n<h3>Conditional Rendering<\/h3>\n<p>In ReactJS, we can create distinct components that summery the behavior we need. After hen, we can render only some of them, depending on the state of our application.<\/p>\n<p>So, Conditional rendering in ReactJS works the same way conditions work in JavaScript. Also, it uses JavaScript operators like <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Statements\/if...else\">if<\/a> or the <a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Operators\/Conditional_Operator\">conditional operator<\/a> to create elements representing the current state, and let ReactJS update the UI to match them.<\/p>\n<h5>Consider these two components below the code:<\/h5>\n<pre class=\"prettyprint\">\r\n<div>function UserGreeting(props) {<\/div>\r\n<div>\u00a0 return &lt;h1&gt;Welcome back!&lt;\/h1&gt;;<\/div>\r\n<div>}<\/div>\r\n<div><\/div>\r\n<div>function GuestGreeting(props) {<\/div>\r\n<div>\u00a0 return &lt;h1&gt;Please sign up.&lt;\/h1&gt;;<\/div>\r\n<div>}<\/div>\r\n<\/pre>\n<p>After then we will create or make a <strong>Greeting<\/strong> component that displays either of these components depending on whether a user is logged in like below:<\/p>\n<pre class=\"prettyprint\">\r\n<div>function Greeting(props) {<\/div>\r\n<div>\u00a0 const isLoggedIn = props.isLoggedIn;<\/div>\r\n<div>\u00a0 if (isLoggedIn) {<\/div>\r\n<div>\u00a0 \u00a0 return &lt;UserGreeting \/&gt;;<\/div>\r\n<div>\u00a0 }<\/div>\r\n<div>\u00a0 return &lt;GuestGreeting \/&gt;;<\/div>\r\n<div>}<\/div>\r\n<div><\/div>\r\n<div>const root = ReactDOM.createRoot(document.getElementById('root'));<\/div>\r\n<div>\/\/ Try changing to isLoggedIn={true}:<\/div>\r\n<div>root.render(&lt;Greeting isLoggedIn={false} \/&gt;);<\/div>\r\n<\/pre>\n<h3>Element Variables<\/h3>\n<p>Now, we can use variables in-store elements. So, it can help us conditionally render a part of the component while the rest of the output doesn\u2019t change.<\/p>\n<h5><em><strong>You can purchase your\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">hosting from Cloudsurph.com<\/a>,\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">Cloudsurph hosting<\/a>\u00a0is a reliable hosting option for business and personal projects. We offer insight and help on system configuration issues and code errors or bugs<\/strong>.<\/em><\/h5>\n<p>Let\u2019s consider these two new components representing the Logout and Login buttons:<\/p>\n<pre class=\"prettyprint\">\r\n<div>function LoginButton(props) {<\/div>\r\n<div>\u00a0 return (<\/div>\r\n<div>\u00a0 \u00a0 &lt;button onClick={props.onClick}&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 Login<\/div>\r\n<div>\u00a0 \u00a0 &lt;\/button&gt;<\/div>\r\n<div>\u00a0 );<\/div>\r\n<div>}<\/div>\r\n<div><\/div>\r\n<div>function LogoutButton(props) {<\/div>\r\n<div>\u00a0 return (<\/div>\r\n<div>\u00a0 \u00a0 &lt;button onClick={props.onClick}&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 Logout<\/div>\r\n<div>\u00a0 \u00a0 &lt;\/button&gt;<\/div>\r\n<div>\u00a0 );<\/div>\r\n<div>}<\/div>\r\n<\/pre>\n<h6><em>So, like the below example, we will create a <a href=\"https:\/\/reactjs.org\/docs\/state-and-lifecycle.html#adding-local-state-to-a-class\">stateful component<\/a> that we called <strong>LoginControl<\/strong>.<\/em><\/h6>\n<p>Here, it will render either <strong>&lt;LoginButton \/&gt;<\/strong> or <strong>&lt;LogoutButton \/&gt;<\/strong> depending on its current state and it will also render a <strong>&lt;Greeting \/&gt;<\/strong> from the previous example like below:<\/p>\n<pre class=\"prettyprint\">\r\n<div>class LoginControl extends React.Component {<\/div>\r\n<div>\u00a0 constructor(props) {<\/div>\r\n<div>\u00a0 \u00a0 super(props);<\/div>\r\n<div>\u00a0 \u00a0 this.handleLoginClick = this.handleLoginClick.bind(this);<\/div>\r\n<div>\u00a0 \u00a0 this.handleLogoutClick = this.handleLogoutClick.bind(this);<\/div>\r\n<div>\u00a0 \u00a0 this.state = {isLoggedIn: false};<\/div>\r\n<div>\u00a0 }<\/div>\r\n<div><\/div>\r\n<div>\u00a0 handleLoginClick() {<\/div>\r\n<div>\u00a0 \u00a0 this.setState({isLoggedIn: true});<\/div>\r\n<div>\u00a0 }<\/div>\r\n<div><\/div>\r\n<div>\u00a0 handleLogoutClick() {<\/div>\r\n<div>\u00a0 \u00a0 this.setState({isLoggedIn: false});<\/div>\r\n<div>\u00a0 }<\/div>\r\n<div><\/div>\r\n<div>\u00a0 render() {<\/div>\r\n<div>\u00a0 \u00a0 const isLoggedIn = this.state.isLoggedIn;<\/div>\r\n<div>\u00a0 \u00a0 let button;<\/div>\r\n<div>\u00a0 \u00a0 if (isLoggedIn) {<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 button = &lt;LogoutButton onClick={this.handleLogoutClick} \/&gt;;<\/div>\r\n<div>\u00a0 \u00a0 } else {<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 button = &lt;LoginButton onClick={this.handleLoginClick} \/&gt;;<\/div>\r\n<div>\u00a0 \u00a0 }<\/div>\r\n<div><\/div>\r\n<div>\u00a0 \u00a0 return (<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 &lt;div&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 \u00a0 &lt;Greeting isLoggedIn={isLoggedIn} \/&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 \u00a0 {button}<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 &lt;\/div&gt;<\/div>\r\n<div>\u00a0 \u00a0 );<\/div>\r\n<div>\u00a0 }<\/div>\r\n<div>}<\/div>\r\n<div><\/div>\r\n<div>const root = ReactDOM.createRoot(document.getElementById('root'));<\/div>\r\n<div>root.render(&lt;LoginControl \/&gt;);<\/div>\r\n<\/pre>\n<h3>Inline If with Logical &amp;&amp; Operator<\/h3>\n<p>Now, here you may <a href=\"https:\/\/reactjs.org\/docs\/introducing-jsx.html#embedding-expressions-in-jsx\">embed expressions in JSX<\/a> by wrapping them in curly braces.<\/p>\n<p><strong><em>You can check our article:\u00a0<a href=\"https:\/\/www.cloudsurph.com\/adonisjs-rest-api-crud-setup\/\">AdonisJS: REST API simple CRUD Operation<\/a>. IF you want then buy a good, reliable, secure web\u00a0<a href=\"https:\/\/www.cloudsurph.com\/windows-vps-hosting\/\">hosting<\/a>\u00a0service \u00a0from here:\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">click here<\/a><\/em><\/strong><\/p>\n<p>Also, this includes the JavaScript logical <strong>&amp;&amp;<\/strong> operator. So, it can be handy for conditionally including an element like the below:<\/p>\n<pre class=\"prettyprint\">\r\n<div>function Mailbox(props) {<\/div>\r\n<div>\u00a0 const unreadMessages = props.unreadMessages;<\/div>\r\n<div>\u00a0 return (<\/div>\r\n<div>\u00a0 \u00a0 &lt;div&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 &lt;h1&gt;Hello!&lt;\/h1&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 {unreadMessages.length &gt; 0 &amp;&amp;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 \u00a0 &lt;h2&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 You have {unreadMessages.length} unread messages.<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 \u00a0 &lt;\/h2&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 }<\/div>\r\n<div>\u00a0 \u00a0 &lt;\/div&gt;<\/div>\r\n<div>\u00a0 );<\/div>\r\n<div>}<\/div>\r\n<div><\/div>\r\n<div>const messages = ['React', 'Re: React', 'Re:Re: React'];<\/div>\r\n<div><\/div>\r\n<div>const root = ReactDOM.createRoot(document.getElementById('root'));<\/div>\r\n<div>root.render(&lt;Mailbox unreadMessages={messages} \/&gt;);<\/div>\r\n<\/pre>\n<p>Therefore, if the condition is true and the element right after <strong>&amp;&amp;<\/strong> will appear in the output and if it is false, then ReactJS will ignore and skip it.<\/p>\n<pre class=\"prettyprint\">\r\nrender() {\r\nconst count = 0;\r\nreturn (\r\n&lt;div&gt;\r\n{count &amp;&amp; &lt;h1&gt;Messages: {count}&lt;\/h1&gt;}\r\n&lt;\/div&gt;\r\n);\r\n}\r\n<\/pre>\n<h3>Inline If-Else with Conditional Operator<strong>\u00a0<\/strong><\/h3>\n<p>Now, we can try another method for conditionally rendering elements inline is to use the JavaScript conditional operator\u00a0<a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Operators\/Conditional_Operator\">condition? true : false.<\/a><\/p>\n<p>See the example below, we are using it to conditionally render a small block of text.<\/p>\n<pre class=\"prettyprint\">\r\nrender() {\r\nconst isLoggedIn = this.state.isLoggedIn;\r\nreturn (\r\n&lt;div&gt;\r\nThe user is &lt;b&gt;{isLoggedIn ? 'currently' : 'not'}&lt;\/b&gt; logged in.\r\n&lt;\/div&gt;\r\n);\r\n}\r\n<\/pre>\n<p>Also, it can also be used for larger expressions although it is less obvious what\u2019s going on with the below code:<\/p>\n<pre class=\"prettyprint\">\r\nrender() {\r\nconst isLoggedIn = this.state.isLoggedIn;\r\nreturn (\r\n&lt;div&gt;\r\n{isLoggedIn\r\n? &lt;LogoutButton onClick={this.handleLogoutClick} \/&gt;\r\n: &lt;LoginButton onClick={this.handleLoginClick} \/&gt;\r\n}\r\n&lt;\/div&gt;\r\n);\r\n}\r\n<\/pre>\n<h3>Preventing Component from Rendering<\/h3>\n<p>Let\u2019s see the example code below, the <strong>&lt;WarningBanner \/&gt;<\/strong> is rendered depending on the value of the prop called <strong>warn<\/strong> and if the value of the prop is <strong>false<\/strong>, then the component does not render like below:<\/p>\n<pre class=\"prettyprint\">\r\n<div>function WarningBanner(props) {<\/div>\r\n<div>\u00a0 if (!props.warn) {<\/div>\r\n<div>\u00a0 \u00a0 return null;<\/div>\r\n<div>\u00a0 }<\/div>\r\n<div><\/div>\r\n<div>\u00a0 return (<\/div>\r\n<div>\u00a0 \u00a0 &lt;div className=\"warning\"&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 Warning!<\/div>\r\n<div>\u00a0 \u00a0 &lt;\/div&gt;<\/div>\r\n<div>\u00a0 );<\/div>\r\n<div>}<\/div>\r\n<div><\/div>\r\n<div>class Page extends React.Component {<\/div>\r\n<div>\u00a0 constructor(props) {<\/div>\r\n<div>\u00a0 \u00a0 super(props);<\/div>\r\n<div>\u00a0 \u00a0 this.state = {showWarning: true};<\/div>\r\n<div>\u00a0 \u00a0 this.handleToggleClick = this.handleToggleClick.bind(this);<\/div>\r\n<div>\u00a0 }<\/div>\r\n<div><\/div>\r\n<div>\u00a0 handleToggleClick() {<\/div>\r\n<div>\u00a0 \u00a0 this.setState(state =&gt; ({<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 showWarning: !state.showWarning<\/div>\r\n<div>\u00a0 \u00a0 }));<\/div>\r\n<div>\u00a0 }<\/div>\r\n<div><\/div>\r\n<div>\u00a0 render() {<\/div>\r\n<div>\u00a0 \u00a0 return (<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 &lt;div&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 \u00a0 &lt;WarningBanner warn={this.state.showWarning} \/&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 \u00a0 &lt;button onClick={this.handleToggleClick}&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {this.state.showWarning ? 'Hide' : 'Show'}<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 \u00a0 &lt;\/button&gt;<\/div>\r\n<div>\u00a0 \u00a0 \u00a0 &lt;\/div&gt;<\/div>\r\n<div>\u00a0 \u00a0 );<\/div>\r\n<div>\u00a0 }<\/div>\r\n<div>}<\/div>\r\n<div><\/div>\r\n<div>const root = ReactDOM.createRoot(document.getElementById('root'));<\/div>\r\n<div>root.render(&lt;Page \/&gt;);<\/div>\r\n<\/pre>\n<p>Finally, returning <strong>null<\/strong> from a component\u2019s <strong>render<\/strong> method does not affect the firing of the component\u2019s lifecycle methods even <strong>componentDidUpdate<\/strong> will still be called.<\/p>\n<p>If you enjoyed reading this article and have more questions please reach out to our\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/submitticket.php?step=2&amp;deptid=1\">support team<\/a>\u00a0via live chat or\u00a0<a href=\"mailto:support@cloudsurph.com\">email<\/a>\u00a0and we would be glad to help you. we provide server\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">hosting<\/a>\u00a0for all types of need and we can even get your\u00a0<a href=\"https:\/\/hosting.cloudsurph.com\/\">server<\/a>\u00a0up and running with the service of your choice.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we can try to define ReactJS: how to use Conditional Rendering, react Conditional Rendering, and how can we use Conditional Rendering in react. Conditional Rendering In ReactJS, we can create distinct components that summery the behavior we need. After hen, we can render only some of them, depending on the state of [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":5347,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[157,25,158,159,151,44,1,31],"tags":[54,47,105,103,48,113],"class_list":["post-5346","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos-7","category-web-hosting-virtualization","category-linux-basics","category-linux-server","category-react-js","category-kvm-xen","category-virtual-private-servers","category-web-hosting","tag-best-vps-hosting-server-maryland","tag-cheap-cloud-servers","tag-cheap-storage-server-hosting","tag-cheapest-vps","tag-dedicated-server-hosting-in-washington-d-c","tag-speed-test-vps"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>how to use Conditional Rendering in ReactJS<\/title>\n<meta name=\"description\" content=\"how to use Conditional Rendering in ReactJS, Conditional Rendering in React, Conditional Rendering in ReactJS\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"how to use Conditional Rendering in ReactJS\" \/>\n<meta property=\"og:description\" content=\"how to use Conditional Rendering in ReactJS, Conditional Rendering in React, Conditional Rendering in ReactJS\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudsurph Web Hosting Washington D.C.\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/CloudSurph\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-14T12:55:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-14T12:55:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2022\/11\/how-to-use-Conditional-Rendering-in-ReactJS.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1264\" \/>\n\t<meta property=\"og:image:height\" content=\"760\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Rony\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cloudsurph\" \/>\n<meta name=\"twitter:site\" content=\"@Cloud_Surph\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rony\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/\"},\"author\":{\"name\":\"Rony\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#\\\/schema\\\/person\\\/ac9b4dd136d96e50d5f29c560191e7ed\"},\"headline\":\"ReactJS: how to use Conditional Rendering\",\"datePublished\":\"2022-11-14T12:55:35+00:00\",\"dateModified\":\"2022-11-14T12:55:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/\"},\"wordCount\":548,\"publisher\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/how-to-use-Conditional-Rendering-in-ReactJS.jpg\",\"keywords\":[\"Best VPS hosting server Maryland\",\"Cheap Cloud Servers\",\"Cheap Storage Server Hosting\",\"Cheapest VPS\",\"Dedicated Server Hosting in Washington D.C\",\"Speed test VPS\"],\"articleSection\":[\"CentOS 7\",\"Cloud Hosting\",\"Linux Basics\",\"Linux Server\",\"React Js\",\"Virtualization\",\"VPS Servers\",\"Web Hosting\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/\",\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/\",\"name\":\"how to use Conditional Rendering in ReactJS\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/how-to-use-Conditional-Rendering-in-ReactJS.jpg\",\"datePublished\":\"2022-11-14T12:55:35+00:00\",\"dateModified\":\"2022-11-14T12:55:52+00:00\",\"description\":\"how to use Conditional Rendering in ReactJS, Conditional Rendering in React, Conditional Rendering in ReactJS\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/how-to-use-Conditional-Rendering-in-ReactJS.jpg\",\"contentUrl\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/how-to-use-Conditional-Rendering-in-ReactJS.jpg\",\"width\":1264,\"height\":760,\"caption\":\"how to use Conditional Rendering in ReactJS\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/reactjs-how-to-use-conditional-rendering\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.cloudsurph.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ReactJS: how to use Conditional Rendering\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#website\",\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/\",\"name\":\"Cloudsurph Web Hosting Washington D.C.\",\"description\":\"Dedicated Server Hosting\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.cloudsurph.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#organization\",\"name\":\"CloudSurph Technology Solutions\",\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2016\\\/04\\\/cloudsurph-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.cloudsurph.com\\\/wp-content\\\/uploads\\\/2016\\\/04\\\/cloudsurph-logo.png\",\"width\":2348,\"height\":1692,\"caption\":\"CloudSurph Technology Solutions\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/CloudSurph\\\/\",\"https:\\\/\\\/x.com\\\/Cloud_Surph\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.cloudsurph.com\\\/#\\\/schema\\\/person\\\/ac9b4dd136d96e50d5f29c560191e7ed\",\"name\":\"Rony\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g\",\"caption\":\"Rony\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/cloudsurph\"],\"url\":\"https:\\\/\\\/www.cloudsurph.com\\\/author\\\/ron\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"how to use Conditional Rendering in ReactJS","description":"how to use Conditional Rendering in ReactJS, Conditional Rendering in React, Conditional Rendering in ReactJS","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/","og_locale":"en_US","og_type":"article","og_title":"how to use Conditional Rendering in ReactJS","og_description":"how to use Conditional Rendering in ReactJS, Conditional Rendering in React, Conditional Rendering in ReactJS","og_url":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/","og_site_name":"Cloudsurph Web Hosting Washington D.C.","article_publisher":"https:\/\/www.facebook.com\/CloudSurph\/","article_published_time":"2022-11-14T12:55:35+00:00","article_modified_time":"2022-11-14T12:55:52+00:00","og_image":[{"width":1264,"height":760,"url":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2022\/11\/how-to-use-Conditional-Rendering-in-ReactJS.jpg","type":"image\/jpeg"}],"author":"Rony","twitter_card":"summary_large_image","twitter_creator":"@cloudsurph","twitter_site":"@Cloud_Surph","twitter_misc":{"Written by":"Rony","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/#article","isPartOf":{"@id":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/"},"author":{"name":"Rony","@id":"https:\/\/www.cloudsurph.com\/#\/schema\/person\/ac9b4dd136d96e50d5f29c560191e7ed"},"headline":"ReactJS: how to use Conditional Rendering","datePublished":"2022-11-14T12:55:35+00:00","dateModified":"2022-11-14T12:55:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/"},"wordCount":548,"publisher":{"@id":"https:\/\/www.cloudsurph.com\/#organization"},"image":{"@id":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/#primaryimage"},"thumbnailUrl":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2022\/11\/how-to-use-Conditional-Rendering-in-ReactJS.jpg","keywords":["Best VPS hosting server Maryland","Cheap Cloud Servers","Cheap Storage Server Hosting","Cheapest VPS","Dedicated Server Hosting in Washington D.C","Speed test VPS"],"articleSection":["CentOS 7","Cloud Hosting","Linux Basics","Linux Server","React Js","Virtualization","VPS Servers","Web Hosting"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/","url":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/","name":"how to use Conditional Rendering in ReactJS","isPartOf":{"@id":"https:\/\/www.cloudsurph.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/#primaryimage"},"image":{"@id":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/#primaryimage"},"thumbnailUrl":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2022\/11\/how-to-use-Conditional-Rendering-in-ReactJS.jpg","datePublished":"2022-11-14T12:55:35+00:00","dateModified":"2022-11-14T12:55:52+00:00","description":"how to use Conditional Rendering in ReactJS, Conditional Rendering in React, Conditional Rendering in ReactJS","breadcrumb":{"@id":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/#primaryimage","url":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2022\/11\/how-to-use-Conditional-Rendering-in-ReactJS.jpg","contentUrl":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2022\/11\/how-to-use-Conditional-Rendering-in-ReactJS.jpg","width":1264,"height":760,"caption":"how to use Conditional Rendering in ReactJS"},{"@type":"BreadcrumbList","@id":"https:\/\/www.cloudsurph.com\/reactjs-how-to-use-conditional-rendering\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.cloudsurph.com\/"},{"@type":"ListItem","position":2,"name":"ReactJS: how to use Conditional Rendering"}]},{"@type":"WebSite","@id":"https:\/\/www.cloudsurph.com\/#website","url":"https:\/\/www.cloudsurph.com\/","name":"Cloudsurph Web Hosting Washington D.C.","description":"Dedicated Server Hosting","publisher":{"@id":"https:\/\/www.cloudsurph.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.cloudsurph.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.cloudsurph.com\/#organization","name":"CloudSurph Technology Solutions","url":"https:\/\/www.cloudsurph.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cloudsurph.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2016\/04\/cloudsurph-logo.png","contentUrl":"https:\/\/www.cloudsurph.com\/wp-content\/uploads\/2016\/04\/cloudsurph-logo.png","width":2348,"height":1692,"caption":"CloudSurph Technology Solutions"},"image":{"@id":"https:\/\/www.cloudsurph.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/CloudSurph\/","https:\/\/x.com\/Cloud_Surph"]},{"@type":"Person","@id":"https:\/\/www.cloudsurph.com\/#\/schema\/person\/ac9b4dd136d96e50d5f29c560191e7ed","name":"Rony","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/40163fe1eb49d5eddd81954e8ad5122633e141df15b0733d07fbe4a156688ba5?s=96&d=mm&r=g","caption":"Rony"},"sameAs":["https:\/\/x.com\/cloudsurph"],"url":"https:\/\/www.cloudsurph.com\/author\/ron\/"}]}},"_links":{"self":[{"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/posts\/5346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/comments?post=5346"}],"version-history":[{"count":2,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/posts\/5346\/revisions"}],"predecessor-version":[{"id":5349,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/posts\/5346\/revisions\/5349"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/media\/5347"}],"wp:attachment":[{"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/media?parent=5346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/categories?post=5346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudsurph.com\/wp-json\/wp\/v2\/tags?post=5346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}