{"id":3293,"date":"2022-12-22T12:58:13","date_gmt":"2022-12-22T12:58:13","guid":{"rendered":"https:\/\/explore.techenutia.com\/?p=3293"},"modified":"2022-12-22T13:05:36","modified_gmt":"2022-12-22T13:05:36","slug":"life-of-a-react-component-the-lifecycle-methods","status":"publish","type":"post","link":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/","title":{"rendered":"LIfe of a React Component: The Lifecycle Methods"},"content":{"rendered":"\n<p>Understanding the lifecycle of a react component is very crucial. It enables you to write code at a certain point in the process. There are basically four important lifecycle methods: componentDidMount, componentDidupdate, componentWillUnmount, shouldComponentUpdate. Let&#8217;s look at these methods in detail. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ComponentDidMount<\/h2>\n\n\n\n<p>componentDidMount is a method that is invoked when the react component is mounted to the DOM. If you need to perform operations like fetching data or setting initial states for different components it is advised to perform such operations in this function. You can&#8217;t update initital states in the component after it has been mounted else it will cause infinite loop.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ComponentDidUpdate<\/h2>\n\n\n\n<p>This is the function called just after the component is updated. When you first load a react component componentDidMount is called and after that with every update componentDidUpdate is called. You can access DOM in this function and mostly any code that interacts with DOM elements is written here. You can also setup setState in this method but with a condition else it will cause a infinite loop. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ShouldComponentUpdate<\/h2>\n\n\n\n<p>shouldComponentUpdate is a method that allows you to alter the updating mechanism of react component. The function returns true by default which leads to normal execution but if you return false it will skip a particular update to the component. You might use this to skip component updates for certain props or state values which you feel aren&#8217;t important to update. But it should always be used with caution because if it is not executed properly it can lead to bugs. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ComponentWillUnmount<\/h2>\n\n\n\n<p>This is a method called when the component is remove from DOM. This method is basically used for certain cleanups. setState shouldn&#8217;t be called in this method because it will never be called. <\/p>\n\n\n\n<p>These are the important lifecycle methods but there are new methods that React team has introduced in recent updates. I would like you to go through the docs to know all these functions. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding the lifecycle of a react component is very crucial. It enables you to write code at a certain point in the process. There are basically four important lifecycle methods: componentDidMount, componentDidupdate, componentWillUnmount, shouldComponentUpdate. Let&#8217;s look at these methods in detail. ComponentDidMount componentDidMount is a method that is invoked when&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/\">Read the post<span class=\"screen-reader-text\">LIfe of a React Component: The Lifecycle Methods<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":3353,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[205],"tags":[],"class_list":["post-3293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-moments","excerpt","zoom","full-without-featured","even","excerpt-0"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.12 (Yoast SEO v26.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>LIfe of a React Component: The Lifecycle Methods | ManOrInfinity<\/title>\n<meta name=\"description\" content=\"What is react lifecycle. The important lifecycle methods. Should you use lifecycle methods.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LIfe of a React Component: The Lifecycle Methods\" \/>\n<meta property=\"og:url\" content=\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/\" \/>\n<meta property=\"og:site_name\" content=\"ManOrInfinity\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-22T12:58:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-12-22T13:05:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/manorinfinity.com\/blog\/wp-content\/uploads\/2022\/12\/React-Native-vs-Reactjs.png?fit=1200%2C600&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"manorinfinity\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@manorinfinity\" \/>\n<meta name=\"twitter:site\" content=\"@manorinfinity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"manorinfinity\" \/>\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\":\"Article\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/\"},\"author\":{\"name\":\"manorinfinity\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"headline\":\"LIfe of a React Component: The Lifecycle Methods\",\"datePublished\":\"2022-12-22T12:58:13+00:00\",\"dateModified\":\"2022-12-22T13:05:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/\"},\"wordCount\":329,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"image\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/manorinfinity.com\/blog\/wp-content\/uploads\/2022\/12\/React-Native-vs-Reactjs.png?fit=1200%2C600&ssl=1\",\"articleSection\":[\"CodeMoments\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/\",\"url\":\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/\",\"name\":\"LIfe of a React Component: The Lifecycle Methods | ManOrInfinity\",\"isPartOf\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/manorinfinity.com\/blog\/wp-content\/uploads\/2022\/12\/React-Native-vs-Reactjs.png?fit=1200%2C600&ssl=1\",\"datePublished\":\"2022-12-22T12:58:13+00:00\",\"dateModified\":\"2022-12-22T13:05:36+00:00\",\"description\":\"What is react lifecycle. The important lifecycle methods. Should you use lifecycle methods.\",\"breadcrumb\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/manorinfinity.com\/blog\/wp-content\/uploads\/2022\/12\/React-Native-vs-Reactjs.png?fit=1200%2C600&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/manorinfinity.com\/blog\/wp-content\/uploads\/2022\/12\/React-Native-vs-Reactjs.png?fit=1200%2C600&ssl=1\",\"width\":1200,\"height\":600},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/manorinfinity.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LIfe of a React Component: The Lifecycle Methods\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#website\",\"url\":\"https:\/\/manorinfinity.com\/blog\/\",\"name\":\"ManOrInfinity\",\"description\":\"Thrive towards greatness\",\"publisher\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/manorinfinity.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\",\"name\":\"manorinfinity\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png\",\"contentUrl\":\"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png\",\"width\":282,\"height\":260,\"caption\":\"manorinfinity\"},\"logo\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/\"},\"description\":\"Complex Problem Solver, Outloud Thinker, An Outstanding Writer, and a very curious human being\",\"sameAs\":[\"http:\/\/manorinfinity.com\"],\"url\":\"https:\/\/manorinfinity.com\/blog\/author\/manorinfinity\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"LIfe of a React Component: The Lifecycle Methods | ManOrInfinity","description":"What is react lifecycle. The important lifecycle methods. Should you use lifecycle methods.","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:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/","og_locale":"en_US","og_type":"article","og_title":"LIfe of a React Component: The Lifecycle Methods","og_url":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/","og_site_name":"ManOrInfinity","article_published_time":"2022-12-22T12:58:13+00:00","article_modified_time":"2022-12-22T13:05:36+00:00","og_image":[{"width":1200,"height":600,"url":"https:\/\/i0.wp.com\/manorinfinity.com\/blog\/wp-content\/uploads\/2022\/12\/React-Native-vs-Reactjs.png?fit=1200%2C600&ssl=1","type":"image\/png"}],"author":"manorinfinity","twitter_card":"summary_large_image","twitter_creator":"@manorinfinity","twitter_site":"@manorinfinity","twitter_misc":{"Written by":"manorinfinity","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#article","isPartOf":{"@id":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/"},"author":{"name":"manorinfinity","@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"headline":"LIfe of a React Component: The Lifecycle Methods","datePublished":"2022-12-22T12:58:13+00:00","dateModified":"2022-12-22T13:05:36+00:00","mainEntityOfPage":{"@id":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/"},"wordCount":329,"commentCount":0,"publisher":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"image":{"@id":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/manorinfinity.com\/blog\/wp-content\/uploads\/2022\/12\/React-Native-vs-Reactjs.png?fit=1200%2C600&ssl=1","articleSection":["CodeMoments"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/","url":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/","name":"LIfe of a React Component: The Lifecycle Methods | ManOrInfinity","isPartOf":{"@id":"https:\/\/manorinfinity.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#primaryimage"},"image":{"@id":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/manorinfinity.com\/blog\/wp-content\/uploads\/2022\/12\/React-Native-vs-Reactjs.png?fit=1200%2C600&ssl=1","datePublished":"2022-12-22T12:58:13+00:00","dateModified":"2022-12-22T13:05:36+00:00","description":"What is react lifecycle. The important lifecycle methods. Should you use lifecycle methods.","breadcrumb":{"@id":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#primaryimage","url":"https:\/\/i0.wp.com\/manorinfinity.com\/blog\/wp-content\/uploads\/2022\/12\/React-Native-vs-Reactjs.png?fit=1200%2C600&ssl=1","contentUrl":"https:\/\/i0.wp.com\/manorinfinity.com\/blog\/wp-content\/uploads\/2022\/12\/React-Native-vs-Reactjs.png?fit=1200%2C600&ssl=1","width":1200,"height":600},{"@type":"BreadcrumbList","@id":"https:\/\/manorinfinity.com\/blog\/2022\/12\/22\/life-of-a-react-component-the-lifecycle-methods\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/manorinfinity.com\/blog\/"},{"@type":"ListItem","position":2,"name":"LIfe of a React Component: The Lifecycle Methods"}]},{"@type":"WebSite","@id":"https:\/\/manorinfinity.com\/blog\/#website","url":"https:\/\/manorinfinity.com\/blog\/","name":"ManOrInfinity","description":"Thrive towards greatness","publisher":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/manorinfinity.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901","name":"manorinfinity","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/","url":"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png","contentUrl":"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png","width":282,"height":260,"caption":"manorinfinity"},"logo":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/"},"description":"Complex Problem Solver, Outloud Thinker, An Outstanding Writer, and a very curious human being","sameAs":["http:\/\/manorinfinity.com"],"url":"https:\/\/manorinfinity.com\/blog\/author\/manorinfinity\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/manorinfinity.com\/blog\/wp-content\/uploads\/2022\/12\/React-Native-vs-Reactjs.png?fit=1200%2C600&ssl=1","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts\/3293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/comments?post=3293"}],"version-history":[{"count":1,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts\/3293\/revisions"}],"predecessor-version":[{"id":3354,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts\/3293\/revisions\/3354"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/media\/3353"}],"wp:attachment":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/media?parent=3293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/categories?post=3293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/tags?post=3293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}