{"id":98526,"date":"2019-10-01T13:00:27","date_gmt":"2019-10-01T10:00:27","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=98526"},"modified":"2019-09-30T15:47:12","modified_gmt":"2019-09-30T12:47:12","slug":"reactjs-lifecycle-methods-tutorial","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html","title":{"rendered":"ReactJS Lifecycle Methods Tutorial"},"content":{"rendered":"<p>In this piece, we are going to dive into the ReactJS lifecycle methods. We explore the events as a component renders to the DOM. Updates to a component trigger additional lifecycle events that we will also look at. We build a simple ticker component and log out method names as they run.<\/p>\n<p>To start off I will be using create-react-app to create skeletal of our project. <code>create-react-app<\/code> is an <code>npm<\/code> package that helps create a starting point for a ReactJS Application. <\/p>\n<p> I have used the below toolset for the application in this article. Some of them are necessary whilst you can switch to your favorites for others.<\/p>\n<ol class=\"wp-block-list\">\n<li><a aria-label=\"create-react-app Package (opens in a new tab)\" href=\"https:\/\/www.npmjs.com\/package\/create-react-app\" target=\"_blank\" rel=\"noreferrer noopener\">create-react-app Package<\/a><\/li>\n<li><a aria-label=\"TypeScript (opens in a new tab)\" href=\"https:\/\/www.npmjs.com\/package\/typescript\" target=\"_blank\" rel=\"noreferrer noopener\">TypeScript<\/a><\/li>\n<li><a aria-label=\"Visual Studio Code IDE (opens in a new tab)\" href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Visual Studio Code IDE<\/a><\/li>\n<\/ol>\n<h2 class=\"wp-block-heading\">1. Initial Setup<\/h2>\n<p>Firstly, we will create our application skeletal using create-react-app. We do this by running the below command on the command prompt.<\/p>\n<pre class=\"brush: bash;\">&gt; npx create-react-app my-app .<\/pre>\n<p>Once the command completes we run the following command to complete setup of our application.<\/p>\n<pre class=\"brush: bash;\">&gt;npm i @types\/react typescript react-app-polyfill<\/pre>\n<p>Now our generated application when opened in Visual Studio Code should look like below:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"330\" height=\"718\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ProjectStructureLifecycleMethodsProject.jpg\" alt=\"ReactJS Lifecycle Methods - Project Structure\" class=\"wp-image-98733\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ProjectStructureLifecycleMethodsProject.jpg 330w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ProjectStructureLifecycleMethodsProject-138x300.jpg 138w\" sizes=\"(max-width: 330px) 100vw, 330px\" \/><figcaption>Project Structure<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">2. Ticker Component<\/h2>\n<p>We create a new React component in a file called Ticker.tsx. This component sets up a ticker using the JavaScript function setInterval. On each passing of the interval a method updateTicker is executed. This method updates the state of the component storing the current datetime in it. The component re renders every 2 seconds since I have set the interval to 2 seconds The code for our component so far looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Ticker.tsx<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import React from 'react';\n\nclass Ticker extends React.Component {\n    timerId = 0;\n    constructor(props: any) {\n        super(props);        \n        this.state = { time: new Date()};\n    }\n    componentDidMount = () =&gt; {\n        this.timerId = setInterval(this.updateTicker, 2000);        \n    }\n    updateTicker: any = () =&gt; {\n        this.setState({ time: new Date() });\n    }\n    render = () =&gt; {   \n        return &lt;div&gt;{this.state.time.toString()}&lt;\/div&gt;;\n    }\n}\nexport default Ticker;\n<\/pre>\n<p>As you might notice in the above code we have already started using lifecycle methods. In particular we leverage the <code>componentDidMount<\/code> lifecycle method to setup our interval. This method is called as the component is initially loaded or mounted into the DOM.<\/p>\n<h2 class=\"wp-block-heading\">3. Demo Component<\/h2>\n<p>This component acts as the parent of our Ticker component. This component, in addition to our Ticker, renders a checkbox that we use to show hide our Ticker component. I will explain the utility of this feature as the article progresses. The code for our Demo Component looks like below and resides in a file named Demo.tsx.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>Demo.tsx<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import React from 'react';\nimport Ticker from '.\/Ticker';\n\nclass Demo extends React.Component{\n    constructor(props: any) {\n        super(props);\n        this.state = { hideTicker: false };\n    }\n    render = () =&gt; {\n        return &lt;div&gt;\n            &lt;input onChange={this.hideTicker} type=\"checkbox\" \/&gt;\n            Hide Ticker \n            { !this.state.hideTicker &amp;&amp; &lt;Ticker \/&gt;}\n        &lt;\/div&gt;;\n    }\n    hideTicker = (event: any) =&gt; {\n        this.setState({ hideTicker: event.target.checked });\n    }\n}\nexport default Demo;\n<\/pre>\n<h2 class=\"wp-block-heading\">4. Initial Render <\/h2>\n<p>The following lifecycle methods run in order as the application starts up. We can leverage them to write code that needs to execute at a particular stage during the lifecycle of a React Component. Let us take a look at these methods.<\/p>\n<ul class=\"wp-block-list\">\n<li>Constructor<\/li>\n<\/ul>\n<p>This is the first method run on Application startup. Typically we call the parent <code>React.Component<\/code> Class constructor passing in the props. As well as initializing the internal state of our Component.<\/p>\n<ul class=\"wp-block-list\">\n<li>getDerivedStateFromProps<\/li>\n<\/ul>\n<p>This method is a static one. And called just before the render method. The props and state of the component are passed to this component. We must either return the updated props and state or null if we do not want to perform any updates. It does not have access to the component instance. We can use this method to update internal state of the Component dependent on prop value changes. The React team discourages use of this method and provides alternatives.<\/p>\n<ul class=\"wp-block-list\">\n<li>render<\/li>\n<\/ul>\n<p>This method is mandatory and required for each Component. It should be a pure function. Meaning that it should not modify or change the state of the component. <\/p>\n<ul class=\"wp-block-list\">\n<li>componentDidMount<\/li>\n<\/ul>\n<p>Upon mounting or rendering of the component this lifecycle method is immediately invoked. This method is the place to put any code for network requests to pull data. <\/p>\n<p>Our Ticker component with the above described lifecycle methods implemented looks like below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Ticker.tsx<\/em><\/span><\/p>\n<pre class=\"brush: js;\">import React from 'react';\n\nclass Ticker extends React.Component {\n    timerId = 0;\n    constructor(props: any) {\n        super(props);        \n        this.state = { time: new Date()};\n        console.log(\"constructor\");\n    }\n    updateTicker: any = () =&gt; {\n        this.setState({ time: new Date() });\n    }\n    static getDerivedStateFromProps = (props: any, state: any) =&gt; {\n        console.log(\"getDerivedStateFromProps\", props, state);\n        return null;\n    }\n    componentDidMount = () =&gt; {\n        console.log(\"componentDiDMount\");\n        this.timerId = setInterval(this.updateTicker, 2000);        \n    }\n    render = () =&gt; {   \n        console.log(\"render\");\n        return &lt;div&gt;{this.state.time.toString()}&lt;\/div&gt;;\n    }\n}\nexport default Ticker;\n<\/pre>\n<p>Now, let us run our application to view the results using the below command:<\/p>\n<pre class=\"brush: js;\">&gt;npm start<\/pre>\n<p>The following is output in the browser&#8217;s console under developer tools.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"744\" height=\"266\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ConsoleOutputLifecycleMethods-1.jpg\" alt=\"ReactJS Lifecycle Methods - Console Output\" class=\"wp-image-98759\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ConsoleOutputLifecycleMethods-1.jpg 744w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ConsoleOutputLifecycleMethods-1-300x107.jpg 300w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><figcaption>Console Output<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">5. Updates Cycle<\/h2>\n<p>I say cycle because over the course of time while the application runs, each component keeps getting updated and is re rendered multiple times. The lifecycle methods that run in order are as below.<\/p>\n<ul class=\"wp-block-list\">\n<li>getDerivedStateFromProps<\/li>\n<\/ul>\n<p>As discussed previously, this lifecycle method runs right before the render method during the initial load. But whilst updating another lifecycle method runs after this and before render method. This method must return null or updated props and state.<\/p>\n<ul class=\"wp-block-list\">\n<li>shouldComponentUpdate<\/li>\n<\/ul>\n<p>This method runs right before render. This method receives the nextProps and nextState of the component. It can inform React if the changes affect the component or not. By returning true or false from this method we can instruct React. This method does not run if forceUpdate is called on a component. If we return false then the following lifecycle methods namely render and componentDidUpdate will not be called. Although this does not prevent the child components from re rendering. With all being said this method of skipping updates is not future proof as React may start treating the return value of false less like a strict directive and more of a hint.<\/p>\n<ul class=\"wp-block-list\">\n<li>render<\/li>\n<\/ul>\n<p>This is the mandatory method that every component must have. It returns either JSX, HTML Markup, Arrays, Fragments, Boolean or null, portal, string or numbers.<\/p>\n<ul class=\"wp-block-list\">\n<li>getSnapshotBeforeUpdate<\/li>\n<\/ul>\n<p>This lifecycle method runs before changes to the DOM. We get a last look at the props and state before updates in this method. Any value returned from this method is passed on to the next in line lifecycle method componentDidUpdate.<\/p>\n<ul class=\"wp-block-list\">\n<li>componentDidUpdate<\/li>\n<\/ul>\n<p>This method runs after an update. Although it is not run for the initial load cycle of a component. Actions like placing network request are recommended in this method.<\/p>\n<p>We implement each of the above lifecycle methods and write out to console as each one runs. Our Ticker component code now looks like below:<\/p>\n<pre class=\"brush: js\">import React from 'react';\n\nclass Ticker extends React.Component {\n    timerId = 0;\n    constructor(props: any) {\n        super(props);        \n        this.state = { time: new Date()};\n        console.log(\"constructor\");\n    }\n    updateTicker: any = () =&gt; {\n        this.setState({ time: new Date() });\n    }\n    static getDerivedStateFromProps = (props: any, state: any) =&gt; {\n        console.log(\"getDerivedStateFromProps\", props, state);\n        return null;\n    }\n    getSnapshotBeforeUpdate = (prevProps: any, prevState: any) =&gt; {\n        console.log(\"getSnapshotBeforeUpdate\", prevProps, prevState);\n        return null;\n    }\n    componentDidMount = () =&gt; {\n        console.log(\"componentDiDMount\");\n        this.timerId = setInterval(this.updateTicker, 2000);        \n    }\n    componentDidUpdate = () =&gt; {\n        console.log(\"componentDidUpdate\");\n    }\n    shouldComponentUpdate = (nextProps: Readonly, nextState: Readonly) =&gt; {\n        console.log(\"shouldComponentUpdate\", nextProps, nextState);\n        return true;\n    }\n    render = () =&gt; {   \n        console.log(\"render\");\n        return &lt;div&gt;{this.state.time.toString()}&lt;\/div&gt;;\n    }\n}\nexport default Ticker;\n<\/pre>\n<p>Let us run the application again and look at the console.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"746\" height=\"219\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ConsoleOutputLifecycleMethods-2.jpg\" alt=\"ReactJS Lifecycle Methods\" class=\"wp-image-98761\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ConsoleOutputLifecycleMethods-2.jpg 746w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ConsoleOutputLifecycleMethods-2-300x88.jpg 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><figcaption>Console Output<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">6. Application End<\/h2>\n<p>As the application runs to an end or when a component is unmounted from the DOM. This final lifecycle method is run, namely componentWillUnmount. It is a great place to write cleanup code and release resources to prevent memory leaks. We emulate this condition here using a checkbox to hide our Ticker component which in turn runs this lifecycle method. <\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"765\" height=\"141\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ComponentWillUnmountMethod.jpg\" alt=\"\" class=\"wp-image-98791\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ComponentWillUnmountMethod.jpg 765w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/ComponentWillUnmountMethod-300x55.jpg 300w\" sizes=\"(max-width: 765px) 100vw, 765px\" \/><figcaption>Console Output<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\">7. Download the Source Code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JCG-ReactJS-Lifecycle-Methods-Tutorial-1.zip\"><strong>React Lifecycle Methods Tutorial<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this piece, we are going to dive into the ReactJS lifecycle methods. We explore the events as a component renders to the DOM. Updates to a component trigger additional lifecycle events that we will also look at. We build a simple ticker component and log out method names as they run. To start off &hellip;<\/p>\n","protected":false},"author":82952,"featured_media":92051,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1903],"tags":[1919],"class_list":["post-98526","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-js","tag-reactjs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ReactJS Lifecycle Methods Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn more? Then check out our detailed example on ReactJS Lifecycle Methods! Explore the events as a component renders to the DOM.\" \/>\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.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ReactJS Lifecycle Methods Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more? Then check out our detailed example on ReactJS Lifecycle Methods! Explore the events as a component renders to the DOM.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2019-10-01T10:00:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Siddharth Seth\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Siddharth Seth\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html\"},\"author\":{\"name\":\"Siddharth Seth\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/09c54717e2cc7956aa8a2df61330f18c\"},\"headline\":\"ReactJS Lifecycle Methods Tutorial\",\"datePublished\":\"2019-10-01T10:00:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html\"},\"wordCount\":1018,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"keywords\":[\"Reactjs\"],\"articleSection\":[\"React.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html\",\"name\":\"ReactJS Lifecycle Methods Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"datePublished\":\"2019-10-01T10:00:27+00:00\",\"description\":\"Interested to learn more? Then check out our detailed example on ReactJS Lifecycle Methods! Explore the events as a component renders to the DOM.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/react-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/reactjs-lifecycle-methods-tutorial.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"React.js\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\\\/react-js\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"ReactJS Lifecycle Methods Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/09c54717e2cc7956aa8a2df61330f18c\",\"name\":\"Siddharth Seth\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g\",\"caption\":\"Siddharth Seth\"},\"description\":\"Siddharth is a Software Development Professional with a Master degree in Computer Applications from IGNOU. He has over 14 years of experience. And currently focused on Software Architecture, Cloud Computing, JavaScript Frameworks for Client and Server, Business Intelligence.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/siddharth-seth-240180\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/siddharth_seth1980\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ReactJS Lifecycle Methods Tutorial - Java Code Geeks","description":"Interested to learn more? Then check out our detailed example on ReactJS Lifecycle Methods! Explore the events as a component renders to the DOM.","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.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html","og_locale":"en_US","og_type":"article","og_title":"ReactJS Lifecycle Methods Tutorial - Java Code Geeks","og_description":"Interested to learn more? Then check out our detailed example on ReactJS Lifecycle Methods! Explore the events as a component renders to the DOM.","og_url":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2019-10-01T10:00:27+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","type":"image\/jpeg"}],"author":"Siddharth Seth","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Siddharth Seth","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html"},"author":{"name":"Siddharth Seth","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/09c54717e2cc7956aa8a2df61330f18c"},"headline":"ReactJS Lifecycle Methods Tutorial","datePublished":"2019-10-01T10:00:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html"},"wordCount":1018,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","keywords":["Reactjs"],"articleSection":["React.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html","url":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html","name":"ReactJS Lifecycle Methods Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","datePublished":"2019-10-01T10:00:27+00:00","description":"Interested to learn more? Then check out our detailed example on ReactJS Lifecycle Methods! Explore the events as a component renders to the DOM.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/react-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/reactjs-lifecycle-methods-tutorial.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/www.javacodegeeks.com\/category\/web-development"},{"@type":"ListItem","position":3,"name":"JavaScript","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript"},{"@type":"ListItem","position":4,"name":"React.js","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript\/react-js"},{"@type":"ListItem","position":5,"name":"ReactJS Lifecycle Methods Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/09c54717e2cc7956aa8a2df61330f18c","name":"Siddharth Seth","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86a5133a5e9d79f7997e2649b1afe58e895c0d88df47b3359103ec4c1a2077d6?s=96&d=mm&r=g","caption":"Siddharth Seth"},"description":"Siddharth is a Software Development Professional with a Master degree in Computer Applications from IGNOU. He has over 14 years of experience. And currently focused on Software Architecture, Cloud Computing, JavaScript Frameworks for Client and Server, Business Intelligence.","sameAs":["https:\/\/www.linkedin.com\/in\/siddharth-seth-240180\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/siddharth_seth1980"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/98526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/82952"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=98526"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/98526\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/92051"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=98526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=98526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=98526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}