<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":3963,"date":"2022-03-21T11:53:19","date_gmt":"2022-03-21T11:53:19","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=3963"},"modified":"2022-03-29T12:15:30","modified_gmt":"2022-03-29T12:15:30","slug":"what-is-state-and-props","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/","title":{"rendered":"What is State and Props ?"},"content":{"rendered":"<h3 id=\"state\"><strong>State:<\/strong><\/h3>\n<ul>\n<li style=\"text-align: justify;\">It is an updatable structure that is used to contain data or information about the component and can change over time.<\/li>\n<li style=\"text-align: justify;\">State\u00a0<strong>Can be modified using this.setState. <\/strong>State can be<strong> asynchronous<\/strong><\/li>\n<li style=\"text-align: justify;\">The component can be directly accessed or modified inside the component.<\/li>\n<li style=\"text-align: justify;\">It is kept as simple as possible.<\/li>\n<li style=\"text-align: justify;\">It represents the component&#8217;s local state or information.<\/li>\n<\/ul>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-4045 size-full\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1.jpg\" alt=\"\" width=\"458\" height=\"288\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1.jpg 458w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1-300x189.jpg 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1-390x245.jpg 390w\" sizes=\"(max-width: 458px) 100vw, 458px\" \/><\/p>\n<p>For Example,<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">class Test extends React.Component {    <br\/>    constructor() {    <br\/>        this.state = {      <br\/>            id: 1,      <br\/>            name: &quot;kaashiv&quot;    <br\/>        };  <br\/>    }    <br\/>    <br\/>    render() {    <br\/>        return (      <br\/>            &lt;div&gt;        <br\/>              &lt;p&gt;{this.state.id}&lt;\/p&gt;        <br\/>              &lt;p&gt;{this.state.name}&lt;\/p&gt;      <br\/>            &lt;\/div&gt;    <br\/>        );  <br\/>    }<br\/>}<\/code><\/pre> <\/div>\n<h3 id=\"props\">Props:<\/h3>\n<ul>\n<li>In UI that components in React are used again and again.<\/li>\n<li>In the component, we need to change the content inside.<\/li>\n<li>It is an object which stores the value of attributes of a tag and works similarly to the HTML attributes.<\/li>\n<li>From one component to other components, It allows the passing of data.<\/li>\n<li>While inside the component we cannot modify the props, because they are immutable.<\/li>\n<li>They are used to passing data between React components.<\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-4047 size-full\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-state-1.jpg\" alt=\"\" width=\"460\" height=\"255\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-state-1.jpg 460w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-state-1-300x166.jpg 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-state-1-390x216.jpg 390w\" sizes=\"(max-width: 460px) 100vw, 460px\" \/><\/p>\n<p>For Example,<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">class ParentComponent extends Component {    <br\/>    render() {    <br\/>        return (        <br\/>            &lt;ChildComponent name=&quot;Second Child&quot; \/&gt;    <br\/>        );  <br\/>    }<br\/>}<br\/><br\/>const ChildComponent = (props) =&gt; {    <br\/>    return &lt;p&gt;{props.name}&lt;\/p&gt;; <\/code><\/pre> <\/div>\n<h3 id=\"difference-between-state-and-props\"><strong>Difference between State and Props :<\/strong><\/h3>\n<table width=\"635\">\n<tbody>\n<tr>\n<td width=\"318\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0<strong><em>State<\/em><\/strong><\/td>\n<td width=\"318\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0<em>Props<\/em><\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"318\">Data passed within the component only.<\/td>\n<td width=\"318\">\u00a0Data passed from one component To another.<\/td>\n<\/tr>\n<tr>\n<td width=\"318\">It becomes Mutable.<\/td>\n<td width=\"318\">\u00a0It becomes immutable<\/td>\n<\/tr>\n<tr>\n<td width=\"318\">It is for both read and write.<\/td>\n<td width=\"318\">\u00a0It is only for read.<\/td>\n<\/tr>\n<tr>\n<td width=\"318\">It becomes long for properties.<\/td>\n<td width=\"318\">It becomes short for properties.<\/td>\n<\/tr>\n<tr>\n<td width=\"318\">It can be modified.<\/td>\n<td width=\"318\">It cannot be modified.<\/td>\n<\/tr>\n<tr>\n<td width=\"318\">Performance is worse.<\/td>\n<td width=\"318\">Performance is better.<\/td>\n<\/tr>\n<tr>\n<td width=\"318\">It should be managed in your view-controller<\/td>\n<td width=\"318\">It is used to pass data down from your view-controller<\/td>\n<\/tr>\n<tr>\n<td width=\"318\">It pass down with props instead.<\/td>\n<td width=\"318\">It is used to\u00a0pass data to child components.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>State: It is an updatable structure that is used to contain data or information about the component and can change over time. State\u00a0Can be modified using this.setState. State can be asynchronous The component can be directly accessed or modified inside the component. It is kept as simple as possible. It represents the component&#8217;s local state [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[16542],"tags":[16632,16636,16638,16627,16639,16631,16626,16633,16634,16629,16628,16635,16637,16642,16643,16641,16640,16630],"class_list":["post-3963","post","type-post","status-publish","format-standard","hentry","category-reactjs","tag-difference-between-props-and-state-in-react-with-example","tag-props-and-state-in-react","tag-props-in-react","tag-props-vs-state-in-react","tag-props-vs-this-props","tag-react-state","tag-reactjs-state-vs-props","tag-state-and-props-in-react-js","tag-state-and-props-in-react-native","tag-state-vs-props","tag-what-are-the-difference-between-props-and-state","tag-what-is-props-in-react-js","tag-what-is-state-in-react","tag-what-is-stats-and-props-in-angular","tag-what-is-stats-and-props-in-html","tag-what-is-stats-and-props-in-javascript","tag-what-is-stats-and-props-in-react","tag-what-is-the-difference-between-state-and-props-in-react"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is State and Props ? - ReactJS Interview Questions and Answers<\/title>\n<meta name=\"description\" content=\"What is State and Props ? - It is an updatable structure that is used to contain data or information about the component and can change over time.\" \/>\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.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is State and Props ? - ReactJS Interview Questions and Answers\" \/>\n<meta property=\"og:description\" content=\"What is State and Props ? - It is an updatable structure that is used to contain data or information about the component and can change over time.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-21T11:53:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-29T12:15:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1.jpg\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/\",\"name\":\"What is State and Props ? - ReactJS Interview Questions and Answers\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1.jpg\",\"datePublished\":\"2022-03-21T11:53:19+00:00\",\"dateModified\":\"2022-03-29T12:15:30+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is State and Props ? - It is an updatable structure that is used to contain data or information about the component and can change over time.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1.jpg\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1.jpg\",\"width\":458,\"height\":288},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\/\/www.wikitechy.com\/interview-questions\"],\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is State and Props ? - ReactJS Interview Questions and Answers","description":"What is State and Props ? - It is an updatable structure that is used to contain data or information about the component and can change over time.","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.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/","og_locale":"en_US","og_type":"article","og_title":"What is State and Props ? - ReactJS Interview Questions and Answers","og_description":"What is State and Props ? - It is an updatable structure that is used to contain data or information about the component and can change over time.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/","og_site_name":"Wikitechy","article_published_time":"2022-03-21T11:53:19+00:00","article_modified_time":"2022-03-29T12:15:30+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1.jpg"}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/","name":"What is State and Props ? - ReactJS Interview Questions and Answers","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1.jpg","datePublished":"2022-03-21T11:53:19+00:00","dateModified":"2022-03-29T12:15:30+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is State and Props ? - It is an updatable structure that is used to contain data or information about the component and can change over time.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/reactjs\/what-is-state-and-props\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1.jpg","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/03\/what-is-props-1.jpg","width":458,"height":288},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/3963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=3963"}],"version-history":[{"count":3,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/3963\/revisions"}],"predecessor-version":[{"id":4048,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/3963\/revisions\/4048"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=3963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=3963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=3963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}