{"id":7073,"date":"2021-12-09T13:11:25","date_gmt":"2021-12-09T07:41:25","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=7073"},"modified":"2021-12-09T18:21:27","modified_gmt":"2021-12-09T12:51:27","slug":"class-component-vs-functional-component","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/","title":{"rendered":"Class component vs functional component"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">In React Native mainly two types of components Class Component &amp; Functional Component.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Class components are <strong>ECMAScript2015(ES6)<\/strong> that extend a base class from React called Component. It is used as a container component to handle <\/span><span style=\"font-weight: 400;\">state management.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Before introducing the concept of hooks in React 16.8 functional component is a plain javascript function but after hooks it maintains <\/span><span style=\"font-weight: 400;\">have state and lifecycle also.\u00a0\u00a0<\/span><\/p>\n<p><strong>Class Component Vs Functional Component:-<\/strong><\/p>\n<p><strong>Class Component:<\/strong><\/p>\n<ol>\n<li><span style=\"font-weight: 400;\"> In the class component, the render method is used when the state of the component is changed.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> It is a Stateful component.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> It requires extending from React Component and creating render function which returns a React element.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> It is used the Complex lifecycle method.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> Required &#8220;this&#8221; keyword for referring to the object itself.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> Lifecycle of class components are:-<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<strong>(a) Mount:<\/strong> It includes methods that are called in the following order when an instance of a component is being created and inserted.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0(i)<\/span><\/p>\n<pre class=\"lang:default decode:true\">static getDerivedStateFromProps(props, state) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(\u201cGetDerivedStateFromProps\u201d);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return null;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">\u00a0(ii)<\/span><\/p>\n<pre class=\"lang:default decode:true \">componentDidMount() {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(\u201cComponentDidMount\u201d);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/pre>\n<p><span style=\"font-weight: 400;\"><strong>(b) Update:<\/strong> It includes an update that can be caused by changes to props or state. These methods are called in the following order when a component is re-rendered:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">(i)\u00a0 \u00a0 \u00a0<\/span><\/p>\n<pre class=\"lang:default decode:true\">getDerivedStateFromProps(props, state) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(\u201cGetDerivedStateFromProps\u201d);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return null;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/pre>\n<p><span style=\"font-weight: 400;\">(ii)<\/span><\/p>\n<pre class=\"lang:default decode:true\">shouldComponentUpdate(nextProps, nextState) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(nextProps, nextState);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(this.props, this.state);\r\n\r\n\r\n\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return false;\u00a0\u00a0\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},<\/pre>\n<p><span style=\"font-size: 1rem;\">(iii)<\/span><\/p>\n<pre class=\"lang:default decode:true \">getSnapshotBeforeUpdate(prevProps, prevState) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(\u201cGetSnapshotBeforeUpdate\u201d);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return null;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/pre>\n<p><span style=\"font-weight: 400;\">(iv)<\/span><\/p>\n<pre class=\"lang:default decode:true\">componentDidUpdate(prevProps, prevState, snapshot) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.log(\u201cComponentDidUpdate\u201d)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\"><strong>(c) Unmount:<\/strong> It includes a method is called when a component is removed.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">(i)<\/span><\/p>\n<pre class=\"lang:default decode:true\">componentWillUnmount(){\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0console.warn('componentWillUnmount call')\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0alert('User has been deleted');\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}.<\/pre>\n<ol start=\"7\">\n<li><strong>The basic syntax of class Component using state:-<\/strong><\/li>\n<\/ol>\n<pre class=\"lang:default decode:true \">import React, { Component } from 'react';\r\n\r\n\u00a0\u00a0import {View,Text,Button} from 'react-native';\r\n\r\n\u00a0\u00a0\u00a0class Example extends React.Component {\r\n\r\n\u00a0\u00a0\u00a0constructor(props) {\r\n\r\n\u00a0\u00a0\u00a0super(props);\r\n\r\n\u00a0\u00a0\u00a0this.state = {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0count: 0\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0};\r\n\r\n\u00a0\u00a0\u00a0}<\/pre>\n<pre class=\"lang:default decode:true \">render() {\r\n\r\n\u00a0\u00a0\u00a0return (\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0&lt;View&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Text&gt;count: {this.state.count} times&lt;\/Text&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Button onClick={() =&gt; this.setState({ count: this.state.count + 1 })}&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Click\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/Button&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/View&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0);\r\n\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0}<\/pre>\n<p><strong>Functional Component:<\/strong><\/p>\n<p><span style=\"font-size: 1rem;\">In Functional Component, render the UI based on props.<\/span><\/p>\n<ol>\n<li><span style=\"font-weight: 400;\"> It is used a stateless component.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> It is a javascript function that accepts props as an argument and returns a React Component.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> Easier or simpler lifecycle.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> Not Required &#8220;this&#8221; keyword for referring to object.<\/span><\/li>\n<li><span style=\"font-weight: 400;\"> Lifecycle of class components are:-<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">\u00a0<strong>(a) Mount:<\/strong> It includes when you want to perform an action each time renders and mount.<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0\u00a0<\/span><\/p>\n<pre class=\"lang:default decode:true\">(i) useEffect( ()=&gt;{},[prop1, prop2])\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(ii) useEffect( ()=&gt; {},[]).<\/pre>\n<p><span style=\"font-weight: 400;\"><strong>(b) Update:<\/strong> It includes when you want to perform an action on component update.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span><\/p>\n<pre class=\"lang:default decode:true\">\u00a0\u00a0(i)\u00a0 useEffect( ()=&gt;{},[prop1, prop2])\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(ii) custom hook used for previous state.\u00a0 useGetSnapshotBeforeUpdate((prevProps, prevState) =&gt; {})\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(iii)useEffect( ()=&gt;{})\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(iv) useMemo().\r\n\r\n\u00a0\u00a0\u00a0\u00a0(c) Unmount: It includes when you want to perform an action only on a component unmount.\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0(i) useEffect( ()=&gt;{return()=&gt;{\/\/cleanup}},[])<\/pre>\n<p><strong>7. Basic Syntax functional component using state:-<\/strong><\/p>\n<pre class=\"lang:default decode:true\">import React, { useState } from 'react';\r\n\r\nimport {View,Text} from 'react-native';\r\n\r\nfunction Example() {\r\n\r\n\u00a0\r\n\r\n\u00a0\u00a0const [count, setCount] = useState(0);\r\n\r\n\r\n\r\n\r\n\u00a0\u00a0return (\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;View&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Text&gt;You clicked {count} times&lt;\/Text&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;Button onClick={() =&gt; setCount(count + 1)}&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Click me\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/Button&gt;\r\n\r\n\u00a0\u00a0\u00a0\u00a0&lt;\/View&gt;\r\n\r\n\u00a0\u00a0);\r\n\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In React Native mainly two types of components Class Component &amp; Functional Component.\u00a0 Class components are ECMAScript2015(ES6) that extend a base class from React called Component. It is used as a container component to handle state management. Before introducing the concept of hooks in React 16.8 functional component is a plain javascript function but after [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7078,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[257,412],"tags":[734,736,735,411,314],"class_list":["post-7073","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react","category-react-native","tag-class","tag-component","tag-functional","tag-react-native","tag-reactjs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Class component vs functional component - InnovationM - Blog<\/title>\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.innovationm.com\/blog\/class-component-vs-functional-component\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Class component vs functional component - InnovationM - Blog\" \/>\n<meta property=\"og:description\" content=\"In React Native mainly two types of components Class Component &amp; Functional Component.\u00a0 Class components are ECMAScript2015(ES6) that extend a base class from React called Component. It is used as a container component to handle state management. Before introducing the concept of hooks in React 16.8 functional component is a plain javascript function but after [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-09T07:41:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-09T12:51:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/12\/Class-component-vs-functional-component-1024x576.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"576\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Class component vs functional component\",\"datePublished\":\"2021-12-09T07:41:25+00:00\",\"dateModified\":\"2021-12-09T12:51:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/\"},\"wordCount\":304,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/Class-component-vs-functional-component.png\",\"keywords\":[\"class\",\"component\",\"functional\",\"react native\",\"Reactjs\"],\"articleSection\":[\"React\",\"React Native\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/\",\"name\":\"Class component vs functional component - InnovationM - Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/Class-component-vs-functional-component.png\",\"datePublished\":\"2021-12-09T07:41:25+00:00\",\"dateModified\":\"2021-12-09T12:51:27+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/Class-component-vs-functional-component.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/Class-component-vs-functional-component.png\",\"width\":3556,\"height\":2000},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/class-component-vs-functional-component\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Class component vs functional component\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Class component vs functional component - InnovationM - Blog","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.innovationm.com\/blog\/class-component-vs-functional-component\/","og_locale":"en_US","og_type":"article","og_title":"Class component vs functional component - InnovationM - Blog","og_description":"In React Native mainly two types of components Class Component &amp; Functional Component.\u00a0 Class components are ECMAScript2015(ES6) that extend a base class from React called Component. It is used as a container component to handle state management. Before introducing the concept of hooks in React 16.8 functional component is a plain javascript function but after [&hellip;]","og_url":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/","og_site_name":"InnovationM - Blog","article_published_time":"2021-12-09T07:41:25+00:00","article_modified_time":"2021-12-09T12:51:27+00:00","og_image":[{"width":1024,"height":576,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/12\/Class-component-vs-functional-component-1024x576.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Class component vs functional component","datePublished":"2021-12-09T07:41:25+00:00","dateModified":"2021-12-09T12:51:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/"},"wordCount":304,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/12\/Class-component-vs-functional-component.png","keywords":["class","component","functional","react native","Reactjs"],"articleSection":["React","React Native"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/","url":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/","name":"Class component vs functional component - InnovationM - Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/12\/Class-component-vs-functional-component.png","datePublished":"2021-12-09T07:41:25+00:00","dateModified":"2021-12-09T12:51:27+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/12\/Class-component-vs-functional-component.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2021\/12\/Class-component-vs-functional-component.png","width":3556,"height":2000},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/class-component-vs-functional-component\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Class component vs functional component"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/7073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=7073"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/7073\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/7078"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=7073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=7073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=7073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}