<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>React JS &gt; Metasys Software Pvt Ltd.</title>
	<atom:link href="https://www.metasyssoftware.com/tag/react-js/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.metasyssoftware.com</link>
	<description>Unique People, Unique Solutions</description>
	<lastBuildDate>Fri, 07 Jun 2024 12:24:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.metasyssoftware.com/wp-content/uploads/2023/10/metasys-svg-.png</url>
	<title>React JS &gt; Metasys Software Pvt Ltd.</title>
	<link>https://www.metasyssoftware.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Effective use of Context in a React Application</title>
		<link>https://www.metasyssoftware.com/react/context-in-react/</link>
		
		<dc:creator><![CDATA[meta_prasad]]></dc:creator>
		<pubDate>Mon, 26 Apr 2021 11:41:15 +0000</pubDate>
				<category><![CDATA[React]]></category>
		<category><![CDATA[Offshore React services]]></category>
		<category><![CDATA[React JS]]></category>
		<category><![CDATA[React developer]]></category>
		<category><![CDATA[React JS development company]]></category>
		<category><![CDATA[React Hooks]]></category>
		<category><![CDATA[React app builder]]></category>
		<category><![CDATA[developer]]></category>
		<category><![CDATA[React bootstrap]]></category>
		<category><![CDATA[Outsourcing React development]]></category>
		<guid isPermaLink="false">https://www.metasyssoftware.com/?p=3550</guid>

					<description><![CDATA[<p>The prerequisite to comprehend this article is a fair knowledge of Hooks. Hooks is a new addition in React 16.8 [&#8230;]</p>
The post <a href="https://www.metasyssoftware.com/react/context-in-react/">Effective use of Context in a React Application</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></description>
										<content:encoded><![CDATA[<p><em>The prerequisite to comprehend this article is a fair knowledge of Hooks. Hooks is a new addition in React 16.8 that let you use state and other React features without writing a class. </em></p>
<p>In a React application, we can pass data from parent component to child components using the prop. However, this is limited to certain type of properties such as Theme, locale preference, etc., which need to be used at global level in the application. With React Context, we can use the data or props without explicitly passing them as props to the component.</p>
<p><strong>Context has three main elements. We need to understand these elements to utilize Context to the fullest. </strong></p>
<ol>
<li><strong>Context Object</strong><strong> &#8211; </strong>The Context object is designed to share data globally in the application.</li>
<li><strong>Context Provider</strong><strong> &#8211; </strong>The Context object comes with a provider that can be used to consume Context data in the React component.</li>
<li><strong>Context Consumer</strong><strong> &#8211;</strong> The Context Consumer is wrapped inside the Context provider, and it is used to get access to the Context data.</li>
</ol>
<p><strong>In this article, let us see how to create a Theme Context using typescript step by step. </strong></p>
<p>1.Create Theme Context Object. Export ThemeContext and set the Context default value to ‘undefined’.</p>
<p><img fetchpriority="high" decoding="async" class="wp-image-3551 size-full aligncenter" title="Theme context object " src="https://www.metasyssoftware.com/wp-content/uploads/Theme-context-object-1.png" alt="Theme context object " width="642" height="231" /></p>
<p>2.Create the Theme object by using two Themes, for instance, here we are going to use ‘dark’ and ‘light’.</p>
<p><img decoding="async" class="aligncenter wp-image-3552 size-full" title="Create Theme Object " src="https://www.metasyssoftware.com/wp-content/uploads/Create-Theme-Object-2.png" alt="Create Theme Object " width="332" height="275" /></p>
<p>3.Create Theme Context provider.</p>
<p><img decoding="async" class="wp-image-3553 size-full aligncenter" title="Theme Context Provider " src="https://www.metasyssoftware.com/wp-content/uploads/Theme-Context-Provider-3.png" alt="Theme Context Provider " width="642" height="408" /></p>
<p>4.We created the Theme Context Provider by setting the Default Theme and function to change the Theme.</p>
<p>5.Subscribe Theme Context by wrapping the component with Context provider.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-3554 size-full" title="SubscribeThemeContext " src="https://www.metasyssoftware.com/wp-content/uploads/SubscribeThemeContext-4.png" alt="SubscribeThemeContext " width="642" height="175" /></p>
<p>6.Use or set the Context data as shown in the screenshot below.</p>
<p><img loading="lazy" decoding="async" class="wp-image-3555 size-full aligncenter" title="Context data React " src="https://www.metasyssoftware.com/wp-content/uploads/Context-data-React-6.png" alt="Context data React " width="642" height="309" /></p>
<p><strong>The concept of Context is simple yet effective. </strong>In this article, we covered how to use Context in the React Application with Theme Context example using TypeScript.</p>
<p>Should you have any queries, please contact MetaSys Software React experts, who have abundant experience in engineering applications using latest dev-tools such as React-Redux, <a href="https://www.metasyssoftware.com/react">React Hooks</a>, React Router, React Bootstrap, etc.</p>
<p>You can reach out to us with any coding queries too! We would be happy to help!</p>
<p style="text-align: center;">Happy Coding!</p>The post <a href="https://www.metasyssoftware.com/react/context-in-react/">Effective use of Context in a React Application</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to implement Internationalization for a React Application</title>
		<link>https://www.metasyssoftware.com/react/how-to-implement-internationalization-for-a-react-application/</link>
					<comments>https://www.metasyssoftware.com/react/how-to-implement-internationalization-for-a-react-application/#respond</comments>
		
		<dc:creator><![CDATA[meta_prasad]]></dc:creator>
		<pubDate>Fri, 20 Nov 2020 12:39:34 +0000</pubDate>
				<category><![CDATA[React]]></category>
		<category><![CDATA[Outsourcing React development company]]></category>
		<category><![CDATA[React JS]]></category>
		<category><![CDATA[React developer]]></category>
		<category><![CDATA[React Native app development]]></category>
		<category><![CDATA[React native developer]]></category>
		<category><![CDATA[React app]]></category>
		<category><![CDATA[React app builder]]></category>
		<category><![CDATA[React Native app development company]]></category>
		<category><![CDATA[React Native development]]></category>
		<category><![CDATA[Outsourcing React development]]></category>
		<category><![CDATA[Offshore React services]]></category>
		<guid isPermaLink="false">http://stage.metasyssoftware.com/?p=3440</guid>

					<description><![CDATA[<p>Internationalization of an application, document or product refers to the development of easy content localization, i.e. modifying the content to [&#8230;]</p>
The post <a href="https://www.metasyssoftware.com/react/how-to-implement-internationalization-for-a-react-application/">How to implement Internationalization for a React Application</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></description>
										<content:encoded><![CDATA[<p>Internationalization of an application, document or product refers to the development of easy content localization, i.e. modifying the content to target the language and culture of the region. Internationalizing an application leads to improved usability by people located across the globe.</p>
<p>There are two main aspects to internationalization, firstly the detection of the user’s local language, and secondly the modification of the content, including translation of the text, and switching relevant items such as currency.</p>
<p>This article addresses how to implement the internationalization of a React application using the library ‘React-intl’. The first step is to create a new React project and add the intl package:</p>
<ul>
<li>Create a React project using the commands –</li>
</ul>
<p><em>$ npx create-react-app project_i18n</em></p>
<p><em>         $ cd project_i18n</em></p>
<ul>
<li>Add the &#8216;react-intl&#8217; package.</li>
</ul>
<p>Configuration of the package consists of four main steps: creating the locales, creating the provider, and finally creating a common translator. In the remainder of this article, I will elaborate on these steps.</p>
<p>1. Create the locales –</p>
<p>a.Create a folder with the name ‘<em>i18n’</em> in your code folder.</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-3227 size-full" title="i18n folder 2" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/iir_1.png" alt="i18n folder 2" width="260" height="229" /></p>
<p>b.Create a file <em>&#8216;locale.js&#8217;</em> and export the locales object.</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-3228 size-full" title="locale js3" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/iir_2.png" alt="locale js3" width="373" height="154" /></p>
<p>2. Create the provider –</p>
<p>a.Now, let’s create the Provider to hook the IntlProvider to the application.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-3229 size-full" title="INTLprovider4" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/iir_3.png" alt="INTLprovider4" width="461" height="307" /><br />
In the above image, IntlProvider is imported from react-intl and a wrapper is created for the application, setting the default locale and passing the message content according to the locale.</p>
<p>b.To create the messages for the respective languages, create a folder called ‘<em>MessageContent’</em> and create the locale files for messages within that folder.<br />
Let us create two different message objects.<br />
For English: &#8211; en-US.js –</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-3231 size-full" title="EN-US5" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/iir_4.png" alt="EN-US5" width="643" height="272" /></p>
<p>For French:- fr-CA.js –</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-3232 size-full" title="FR-CA 6" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/iir_5.png" alt="FR-CA 6" width="643" height="242" /></p>
<p>c. Create an ‘<em>js’</em> file under the MessageContent folder to export the messages.<br />
MessageContent-&gt; index.js –</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-3233 size-full" title="Messagecontent 7" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/iir_6.png" alt="Messagecontent 7" width="642" height="237" /></p>
<p>3. Create a common translator –</p>
<p>a.Let us create a common Translate function to translate the message according to the locale.<br />
i18n-&gt; translate.js –</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-3234 size-full" title="Commontranslator8" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/iir_7.png" alt="Commontranslator8" width="639" height="124" /></p>
<p>b.Create <em>‘index.js’ </em>under the ‘<em>i18n’</em> folder to export the locales and provider as default.<br />
i18n-&gt; index.js –</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-3235 size-full" title="index.js9" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/iir_8.png" alt="index.js9" width="642" height="85" /></p>
<p>c.Finally, let us wrap the application with IntlProvider and set the locale in App.js.<br />
src-&gt; App.js –</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-3236 size-full" title="wrappingapp10" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/iir_9.png" alt="wrappingapp10" width="643" height="520" /></p>
<p>Example for French Locale –</p>
<p>fr-CA.js</p>
<p>export default {</p>
<p>[LOCALES.FRENCH]: { &#8216;hello&#8217;: &#8216;Bonjour&#8217;, &#8216;userName&#8217;: &#8216;le nom d\&#8217; utilisateur est {uname}&#8217;</p>
<p>}</p>
<p>};</p>
<p>translate.js</p>
<p>const translate = (id, value={}) =&gt; &lt;FormattedMessage id={id} values={{…value}}/&gt;</p>
<p>d. We are looking for the following output:</p>
<p>translate(‘hello&#8217;)  =&gt; Bonjour</p>
<p>translate(&#8216;userName&#8217;, {&#8216;uname&#8217;: ‘Sam&#8217;}) =&gt; le nom d&#8217; utilisateur est Sam</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-3237 size-full" title="Bonjour11" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/iir_10.png" alt="Bonjour11" width="659" height="260" /></p>
<p>Internationalization can be achieved in react application by using ‘React-intl&#8217; with minimal development efforts for handling multiple languages.</p>
<p>MetaSys has developed custom React solutions for clients across various industries and geographies. If you have any questions on internationalization in your <a href="https://www.metasyssoftware.com/case-study-react-native">React</a> projects, then please feel free to contact us. Happy coding!</p>The post <a href="https://www.metasyssoftware.com/react/how-to-implement-internationalization-for-a-react-application/">How to implement Internationalization for a React Application</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.metasyssoftware.com/react/how-to-implement-internationalization-for-a-react-application/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>React Redux &#8211; The art of state management</title>
		<link>https://www.metasyssoftware.com/react/react-redux-the-art-of-state-management/</link>
					<comments>https://www.metasyssoftware.com/react/react-redux-the-art-of-state-management/#respond</comments>
		
		<dc:creator><![CDATA[meta_prasad]]></dc:creator>
		<pubDate>Thu, 27 Aug 2020 13:42:18 +0000</pubDate>
				<category><![CDATA[React]]></category>
		<category><![CDATA[React JS development company]]></category>
		<category><![CDATA[React Native app development]]></category>
		<category><![CDATA[React native developer]]></category>
		<category><![CDATA[React web app]]></category>
		<category><![CDATA[React mobile development company]]></category>
		<category><![CDATA[Outsourcing React services]]></category>
		<category><![CDATA[Outsourcing React development]]></category>
		<category><![CDATA[React JS]]></category>
		<category><![CDATA[Offshore React services]]></category>
		<category><![CDATA[React Redux]]></category>
		<category><![CDATA[Outsourcing React development company]]></category>
		<category><![CDATA[React Native]]></category>
		<category><![CDATA[React developer]]></category>
		<guid isPermaLink="false">https://www.metasyssoftware.com/?p=3182</guid>

					<description><![CDATA[<p>React is one of the most popular technologies for front-end development, which uses a component based approach to enable fast [&#8230;]</p>
The post <a href="https://www.metasyssoftware.com/react/react-redux-the-art-of-state-management/">React Redux – The art of state management</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></description>
										<content:encoded><![CDATA[<p><strong>React</strong> is one of the most popular technologies for front-end development, which uses a component based approach to enable fast app development. <strong>Redux</strong> is a predictable state container for JS apps, and works particularly well with React.  In this article, I will be covering some basics on how to set up React-Redux for state management of a UI.</p>
<p>To illustrate the advantages of this approach, have a look at the UI structure shown below.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-3183 size-full" title="UI structure image 1" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_1.png" alt="UI structure image 1" width="643" height="361" /></p>
<p>Let’s say the functionality required is that when a user interacts with the big component, the application has to update the small component and the header. In other words, we need to sync the header and small component as well as manage the states of all the other components. Without a state management library such as the one provided by Redux, coding this implementation can easily become very complicated.</p>
<p>Using the state functionality in React allows only the use of local, component level states.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-3184 aligncenter" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_2.png" alt="Image 2" width="252" height="52" /></p>
<p>You can store the states using setState method, and fetch the stored state using state.[STATE_NAME]. However, these states are local, and only available within the class component in which it is declared.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-3185 size-full" title="Setstate image3" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_3.png" alt="Setstate image3" width="575" height="133" /></p>
<p>To store the states at the application level, i.e. the global level, in order to access them from different components, we can use React-Redux.</p>
<p><strong><u>Let’s see how React-Redux works</u></strong></p>
<p>You will see three main elements in the Redux architecture – Store, Dispatch Actions and Reducers.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-3186 aligncenter" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_4.png" alt="Redux architecture 4" width="642" height="319" /></p>
<p><strong>Store</strong>: holds the states at the application level, and allows any component to get data from the store in the form of Redux States.</p>
<p><strong>Dispatch Action:</strong> a function of the Redux Store to trigger a state change.</p>
<p><strong>Reducers</strong>: It handles the value change in Redux State.</p>
<p><strong><u>How to configure React Redux in a React JS project –</u></strong></p>
<p>The following packages are needed to be installed to configure  Redux in the project &#8211;</p>
<ol>
<li><strong>Redux</strong>: the core package of React Redux.</li>
<li><strong>React-redux:</strong> needed for React bindings.</li>
<li><strong>Redux-thunk: </strong>a middleware which allows you to call action creators, and which returns a function instead of the action object.</li>
</ol>
<p>These dependencies can be installed by using the following NPM command &#8211;<br />
“<strong>npm install redux react-redux redux-thunk &#8211;save</strong>”</p>
<p>After these dependencies are installed, a store can be created and initialized with data/null values as per the requirements. This can be done by creating the file store.js in the project.</p>
<p>First however, you need to create reducer.js to handle the next states. Below is the example of reducer.js to initialize the state. Here, it is just returning the initial value from the reducer.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-3187 size-full" title="reducer.js 5" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_5.png" alt="reducer.js 5" width="447" height="150" /></p>
<p>Below is a slightly more complex example of the code in reducer.js to update the states based on the action executed from the component.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-3188 size-full" title="coding 6" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_6.png" alt="coding 6" width="425" height="261" /></p>
<p>In the above example, it adds the data to the state upon the dispatch action (ADD_DATA). Now let’s create the action to dispatch. You can create a file with the name action.js, that contains the code shown below.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-3189 aligncenter" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_7.png" alt="action.js 7" width="379" height="113" /></p>
<p>Once the action is created, now you can create a store and then connect the store to the application. You can create a file with the name store.js, that contains the code shown below.</p>
<p><img loading="lazy" decoding="async" class="wp-image-3190 size-full aligncenter" title="store.js 8" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_8.png" alt="store.js 8" width="478" height="251" /></p>
<p>To connect the store to the application, you will have to use the entry point. In the index.js (i.e. entry point of the app), import the store as shown below &#8211;</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-3191 aligncenter" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_9.png" alt="coding 9" width="367" height="249" /></p>
<p>These are all the Redux configurations for an application. Refer the the image below to use it in your component –</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-3192 size-full" title="React component 10" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_10.png" alt="React component 10" width="642" height="671" /></p>
<p><a href="https://www.metasyssoftware.com/react">React Redux</a> can handle large amounts of data at the application level with cleaner components and is particularly useful for big applications.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-3193 size-full" title="Without Redux 11" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_11.png" alt="Without Redux 11" width="336" height="317" /></p>
<p><img loading="lazy" decoding="async" class="wp-image-3194 size-full aligncenter" title="With Redux 12" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/RRAM_12.png" alt="With Redux 12" width="336" height="288" /></p>
<p>Without redux, to transfer data from component 1 to component 5, you need to pass it through middle components. This increases the props for components and creates more complexity and the components are less clean.</p>
<p>Using React-Redux, you can get or set the data to the store from any of the components directly by mapping the redux states to component props. In this case, you do not need to pass props to the middle components. This allows for much cleaner components and increased clarity in the code.</p>
<p>If you are looking to build a mobile or web application using React technology, then please feel free to contact us.</p>The post <a href="https://www.metasyssoftware.com/react/react-redux-the-art-of-state-management/">React Redux – The art of state management</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.metasyssoftware.com/react/react-redux-the-art-of-state-management/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Our experience of using React Hooks and what you can learn from it!</title>
		<link>https://www.metasyssoftware.com/react/react-hooks-and-what-you-can-learn-from-it/</link>
					<comments>https://www.metasyssoftware.com/react/react-hooks-and-what-you-can-learn-from-it/#respond</comments>
		
		<dc:creator><![CDATA[meta_prasad]]></dc:creator>
		<pubDate>Fri, 24 Jul 2020 10:51:48 +0000</pubDate>
				<category><![CDATA[React]]></category>
		<category><![CDATA[React development services]]></category>
		<category><![CDATA[React development company]]></category>
		<category><![CDATA[Offshore React services]]></category>
		<category><![CDATA[Outsourcing React development company]]></category>
		<category><![CDATA[React JS]]></category>
		<category><![CDATA[Offshore React development services]]></category>
		<category><![CDATA[React developer]]></category>
		<category><![CDATA[React Native app development]]></category>
		<category><![CDATA[React native developer]]></category>
		<category><![CDATA[React mobile app development]]></category>
		<category><![CDATA[React Hooks]]></category>
		<category><![CDATA[React programming]]></category>
		<guid isPermaLink="false">https://www.metasyssoftware.com/?p=3131</guid>

					<description><![CDATA[<p>React JS is now a very popular programming language. React Hooks has unlocked new capabilities and allows you to create [&#8230;]</p>
The post <a href="https://www.metasyssoftware.com/react/react-hooks-and-what-you-can-learn-from-it/">Our experience of using React Hooks and what you can learn from it!</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></description>
										<content:encoded><![CDATA[<p>React JS is now a very popular programming language. React Hooks has unlocked new capabilities and allows you to create great applications. It allows one to write very compact code. We share our experience of how we have used React Hooks. We assume here that you have some React Programming knowledge.</p>
<p>React Hooks are functions that allow you to hook into React lifecycle and state features. They primarily serve as an alternative for classes. They can help in keeping your components clean and perform better. Hooks are a recent  addition in React version 16.8.0.</p>
<p>In this article, we are going to show you how to convert a React class into a functional component using the useState Hook.</p>
<p>Hooks don’t work inside classes because they let you use React without classes. We will use the built-in hooks instead of React lifecycle methods. Eg. useState, useEffect, useRef etc.</p>
<p>We are covering useState, useEffect, useRef React hooks in this article. useState() is used to replace the constructor functions and state declarations. While useEffect() is used to replace componentDidMount() and componentDidUpdate(). You can use useEffect as many times as you need to in single component. And the last one, useRef has another cool usage besides DOM refs, it is also a generic container whose current property is mutable, it also can hold any value similar to an instance property of a class.</p>
<p><strong>Steps to convert a React class component into a functional component using React Hooks –</strong></p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3132" src="https://www.metasyssoftware.com/wp-content/uploads/2022/07/Our_experience_of_using_React_1.png" alt="React Hooks " width="655" height="512" /></p>
<p>Step 1. Change ‘class ComponentName extends Component’ With ‘function ComponentName(props)‘</p>
<p>Step 2. Remove “this.” And “this.state” from the entire component.</p>
<p>Step 3. import React, { useState } from ‘react’</p>
<p>Step 4. Remove the constructor. Add its logic as shown above in the image for initializing the state variables with the help of useState hook.</p>
<p><strong>Let’s understand conversion into useState, useEffect and useRef with examples –</strong></p>
<ul>
<li><strong>useState() Hook –</strong></li>
</ul>
<p>The parameter of the useState hook is the initial value of the state. This hook provides the array with two values – the first is the name of the state and the second is the function name which updates the value of that state.</p>
<p>Eg.</p>
<p>const [num, setNum] = useState(0); //declaration</p>
<p>setNum(10) //use</p>
<p>Here num is the state name, setCount is the function that you can use anywhere in the component to update that state.</p>
<p>Here are some examples of setting or initializing state variables for different data types –</p>
<p>//Set an Integer</p>
<p>const [num, setNum] = useState(0);</p>
<p>setNum(10);</p>
<p>&nbsp;</p>
<p>//Set a String</p>
<p>const [name, setUsername] = useState(‘John’);</p>
<p>setUsername(‘Smith’);</p>
<p>&nbsp;</p>
<p>//Set a Boolean</p>
<p>const [isValid, setIsValid] = useState(false);</p>
<p>setIsValid(true);</p>
<p>&nbsp;</p>
<p>//Set and Array</p>
<p>const [items, setItems] = useState([]);</p>
<p>setItems([0,1,2,3,4]);</p>
<p>setItems([{id:0, color:”red”},{id:1, color:”green”},{id:2, color:”blue”}]);</p>
<p>&nbsp;</p>
<p>//Set and Object</p>
<p>const [form, setValues] = useState({</p>
<p>id: 0,</p>
<p>firstName: ‘’,</p>
<p>lastName: ‘’,</p>
<p>subscribe: false</p>
<p>})</p>
<p>&nbsp;</p>
<p>setValues({</p>
<p>…form,</p>
<p>firstName: ‘Jamie’,</p>
<p>subscribe: true</p>
<p>})</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ul>
<li><strong>Replace lifecycle methods (compentDidMount, componentWillUnmount,</strong></li>
</ul>
<p><strong> componentWillReceiveProps, componentDidUpdate) with useEffect</strong></p>
<p>&nbsp;</p>
<p>e.g.</p>
<p>const [items, setItems] = useState([]);</p>
<p>const [num, setNum] = useState(0);</p>
<p>&nbsp;</p>
<ol>
<li>compentDidMount</li>
</ol>
<p>&nbsp;</p>
<p>useEffect(()=&gt;{</p>
<p>setItems(items);</p>
<p>}, [])   // Here empty array indicates don&#8217;t look for any updates</p>
<p>&nbsp;</p>
<p>b.componentWillUnmount</p>
<p>&nbsp;</p>
<p>useEffect(()=&gt;{</p>
<p>return () =&gt; {console.log(‘unmounting the component’)}</p>
<p>},[])</p>
<p>&nbsp;</p>
<p>c. componentDidUpdate/componentWillReceiveProps</p>
<p>This will get executed when your ‘num’ state variable and ‘id’ props will get updated.</p>
<p>&nbsp;</p>
<p>useEffect(()=&gt;{</p>
<p>if (!isEmpty(num))</p>
<p>{</p>
<p>console.log(‘num changed = ’,num);</p>
<p>setItems(items);</p>
<p>}</p>
<p>&nbsp;</p>
<p>if(!isEmpty(props.id))</p>
<p>{</p>
<p>console.log(‘props.id changed = ’,props.id);</p>
<p>}</p>
<p>},[num, props.id])</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<ul>
<li><strong>Use of </strong><strong>useRef</strong></li>
</ul>
<p>&nbsp;</p>
<p>const [num, setNum] = useState(0);</p>
<p>const prevNumRef = useRef();</p>
<p>useEffect(()=&gt;{</p>
<p>prevNumRef.current = num;</p>
<p>})</p>
<p>const prevNum = prevNumRef.current;</p>
<p>return &lt;h1&gt;Current value : {num}, previous value = {prevNum}&lt;/h1&gt;</p>
<p>&nbsp;</p>
<p><strong>Advantages</strong></p>
<p>1.With React hooks, the component will be cleaner and easier to read (fewer lines of code). Hooks are easier to work with and to test.</p>
<p>2.It is easy to make code reusable. They don’t create another element in DOM like HOCs in React do.</p>
<p>3. useState &#8211; it allows to update different states with specific functions. The ability to move the state update logic as a separate hook.</p>
<p>&nbsp;</p>
<p><strong>Disadvantages </strong></p>
<p>1.useEffect hook allows to merge three lifecycle methods such as componentDidMount, componentWillUnmount and componentDidUpdate into one and the issue with useEffect is the second parameters ,i.e. the array that we need to pass to define this behaviour. It is not explicit enough.</p>
<p>2.React Hooks are new additions to React. So to convert and test a complex class can be a time-consuming task initially .</p>
<p>3.Since it is relatively a new addition it may not be compatible with all third party libraries. But this is rapidly changing .</p>
<p>This is all about React Hooks in a nutshell. If you are looking to build any a mobile or web application using React technology, then please <a href="https://www.metasyssoftware.com/contact">contact us</a>.</p>
<p>Happy coding!</p>The post <a href="https://www.metasyssoftware.com/react/react-hooks-and-what-you-can-learn-from-it/">Our experience of using React Hooks and what you can learn from it!</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.metasyssoftware.com/react/react-hooks-and-what-you-can-learn-from-it/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Six smart steps to configure Mapbox with ReactJS</title>
		<link>https://www.metasyssoftware.com/react/six-smart-steps-to-configure-mapbox-with-reactjs/</link>
					<comments>https://www.metasyssoftware.com/react/six-smart-steps-to-configure-mapbox-with-reactjs/#respond</comments>
		
		<dc:creator><![CDATA[meta_prasad]]></dc:creator>
		<pubDate>Wed, 13 Nov 2019 11:08:09 +0000</pubDate>
				<category><![CDATA[React]]></category>
		<category><![CDATA[React development services]]></category>
		<category><![CDATA[React Redux]]></category>
		<category><![CDATA[Outsourcing React development]]></category>
		<category><![CDATA[React JS app]]></category>
		<category><![CDATA[Offshore React development services]]></category>
		<category><![CDATA[React JS web app]]></category>
		<category><![CDATA[Custom map]]></category>
		<category><![CDATA[Mapbox studio]]></category>
		<category><![CDATA[Reactjs]]></category>
		<category><![CDATA[Customizing Mapbox]]></category>
		<category><![CDATA[Reactnative]]></category>
		<category><![CDATA[React JS example]]></category>
		<category><![CDATA[mapbox]]></category>
		<category><![CDATA[Configuring Mapbox]]></category>
		<category><![CDATA[React customapp]]></category>
		<category><![CDATA[React JS web development company]]></category>
		<category><![CDATA[React developers]]></category>
		<category><![CDATA[React JS web development]]></category>
		<category><![CDATA[React JS]]></category>
		<guid isPermaLink="false">https://www.metasyssoftware.com/?p=2880</guid>

					<description><![CDATA[<p>Mapbox provides custom maps, search and navigation. It supports many platforms. The tool is powered by programmers as well as [&#8230;]</p>
The post <a href="https://www.metasyssoftware.com/react/six-smart-steps-to-configure-mapbox-with-reactjs/">Six smart steps to configure Mapbox with ReactJS</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></description>
										<content:encoded><![CDATA[<style><span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start">﻿</span>#fm-blog ul li { list-style: none; }</style>
<div id="fm-blog">Mapbox provides custom maps, search and navigation. It supports many platforms. The tool is powered by programmers as well as millions of devices providing Location Data. It provides developers a platform and a toolset to build customized applications where location-based data can be used to meet a variety of business requirements.<br />
<strong>A typical scenario where Mapbox is used:</strong><br />
A service provider uses Mapbox to track locations of their assets or employees in order to provide real-time information to customers or for operational monitoring. This could be a restaurant delivery service, an international transport company or even a fleet operator in a city.<br />
<strong>Customizing Mapbox</strong><br />
One of our clients provides data services to monitor the health of agricultural farms. They wished to offer compelling data visualization of agricultural farm images along with other details. We customized mapbox to render this information on the web and mobile devices. There are SDKs available for the Web, iOS and Android.<br />
<strong>In this article, we share how we configured mapbox in React JS using custom style to add new fonts, custom icons and publish these styles.</strong>Following are the steps involved –<br />
<strong>1. Steps to generate the token number and style in Mapbox</strong></p>
<ul>
<li>a. Create an account on https://account.mapbox.com</li>
<li>b. Log in to your account</li>
<li>c. On the Dashboard look for the Default public token. This Token number can be used for configuration in the Web App. You need to remember that this token number is public and easily accessible from the developer tab.</li>
<li>d. To get the private Token click on the button &#8216;Create a Token&#8217; you will get a form. Enter the &#8216;Token name&#8217; and select the desired &#8216;Public Scope&#8217; and the &#8216;Secret Scopes’.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-2900 size-full" title="Access tokens " src="https://www.metasyssoftware.com/wp-content/uploads/Access-tokens-1-3.png" alt="Access tokens" width="642" height="425" /></li>
<li>e. Note: &#8211; This token will only be accessible from the specific URLs that we add while generating the Token.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-2884 size-full" title="Create an access token" src="https://www.metasyssoftware.com/wp-content/uploads/Create-an-access-token-2.png" alt="Create an access token" width="540" height="409" /><img loading="lazy" decoding="async" class="alignnone wp-image-2901 size-full" src="https://www.metasyssoftware.com/wp-content/uploads/Token-restrictions-3-1.png" alt="Token Restrictions" width="643" height="394" /></li>
<li>f. Now add the list of comma-separated URLs into the URL field and click on the &#8216;Create Token’. Next you will be asked to confirm with your account password.</li>
<li>g. You will find the private token at the bottom of the Token list.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-2902 size-full" title="Private token" src="https://www.metasyssoftware.com/wp-content/uploads/Private-token-4-1.png" alt="Private token" width="625" height="284" /></li>
</ul>
<p><strong>2. Steps to configure React JS app with Mapbox</strong></p>
<ul>
<li>a. There are two different methods available for using the Mapbox on the web App.<br />
We describe the steps using the &#8216;npm&#8217; module bundler for installing Mapbox GL JS.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-2903 size-full" title="Method selection for installing Mapbox" src="https://www.metasyssoftware.com/wp-content/uploads/Method-selection-for-installing-Mapbox-5-1.png" alt="Method selection for installing Mapbox" width="398" height="232" /></li>
<li>b. Install the &#8216;npm&#8217; package &#8211;&gt; &#8216;npm install mapbox-gl &#8211;save&#8217;</li>
<li>c. Include the GL JS CSS file</li>
<li>d. Include the CSS file in theof your HTML file
<div>
<ul>
<li>i.&lt;link href=&#8217;https://api.mapbox.com/mapbox-gl-js/v1.3.1/mapbox-gl.css&#8217; rel=&#8217;stylesheet&#8217; /&gt;</li>
</ul>
</div>
</li>
<li>e. Add the map to your Web App.
<ul>
<li>i. var mapboxgl = require(‘mapbox-gl/dist/mapbox-gl.js&#8217;);</li>
<li>ii. mapboxgl.accessToken = &#8216;Your Token number’;</li>
<li>iii. var map = new mapboxgl.Map({</li>
<li>iv. container: &#8216;YOUR_CONTAINER_ELEMENT_ID&#8217;,</li>
<li>v. style: &#8216;mapbox://styles/mapbox/streets-v11&#8217; // Default style link</li>
<li>vi. });</li>
</ul>
</li>
<li>f.  Now you are done with the configuration.</li>
</ul>
<p><strong>3. Steps to create the custom style of Mapbox</strong></p>
<ul>
<li>a.To create our custom style for the map, we need to open the Mapbox Studio,</li>
<li>b.To open the Mapbox studio, you can to go to the Dashboard and then click on the &#8216;Design in Mapbox Studio&#8217; on the right side of the Dashboard or Just click on the link here <a href="https://studio.mapbox.com/" target="_blank" rel="nofollow noopener noreferrer">https://studio.mapbox.com/</a></li>
<li>c.After opening the Mapbox studio, you can see the predefined styles you can use directly or you may choose to create a new style.<img loading="lazy" decoding="async" class="alignnone wp-image-2904 size-full" title="Mapbox styles" src="https://www.metasyssoftware.com/wp-content/uploads/Mapbox-styles-6-1.png" alt="Mapbox styles" width="642" height="342" /></li>
<li>d. To create a new style, click on the &#8216;New style&#8217; button on top of the page.</li>
<li>e. Select the desired template from the list and can change the style of the map from bottom of the dialog and then click on the customize button.<img loading="lazy" decoding="async" class="alignnone wp-image-2905 size-full" title="Templates" src="https://www.metasyssoftware.com/wp-content/uploads/Templates-7-1.png" alt="Templates" width="642" height="428" /></li>
<li>f. You can see a dashboard with different settings.</li>
<li>g. You can update the style of the country label, background, road, buildings and many more<img loading="lazy" decoding="async" class="alignnone wp-image-2890 size-full" title="Updating style " src="https://www.metasyssoftware.com/wp-content/uploads/Updating-style-8.png" alt="Updating style" width="692" height="326" /><img loading="lazy" decoding="async" class="alignnone wp-image-2891 size-full" title="icons" src="https://www.metasyssoftware.com/wp-content/uploads/icons-9.png" alt="icons" width="642" height="33" /></li>
</ul>
<p><strong>4. Steps to add a new font to the map and then publish for production</strong></p>
<ul>
<li>a. Click on the Fonts tab on the top-right corner then you can find a dialog to upload the new fonts.<img loading="lazy" decoding="async" class="alignnone wp-image-2892 size-full" title="Upload fonts " src="https://www.metasyssoftware.com/wp-content/uploads/upload-fonts-10.png" alt="Upload fonts" width="643" height="367" /></li>
<li>b. Clicking on the Upload new font, you can see a new dialog with the title &#8216;Upload fonts&#8217; here you can drag new fonts with extension &#8216;.TTF&#8217; and ‘.OTF’.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-2893 size-full" title="Upload new font " src="https://www.metasyssoftware.com/wp-content/uploads/upload-new-font-11.png" alt="Upload new font" width="292" height="390" /></li>
<li>c. Once Font family is added, it can be then used in the map.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-2894 size-full" title="icons" src="https://www.metasyssoftware.com/wp-content/uploads/icons-12.png" alt="icons " width="642" height="33" /></li>
</ul>
<p><strong>5. Steps to add a custom icon or an image and publish</strong></p>
<ul>
<li>a. The image we upload here will be available as an icon on the map for example Image as a custom marker.</li>
<li>b. Click on the &#8216;Images&#8217; tab in the header you can see a dialog to upload the SVG image.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-2895 size-full" title="Upload svg" src="https://www.metasyssoftware.com/wp-content/uploads/upload-svg-images-13.png" alt="Upload svg" width="319" height="439" /><img loading="lazy" decoding="async" class="alignnone wp-image-2897 size-full" title="Drag and drop svg images" src="https://www.metasyssoftware.com/wp-content/uploads/drag-and-drop-svg-images-14.png" alt="Drag and drop svg images" width="643" height="411" /></li>
<li>c. To upload the SVG image, click on the &#8216;Upload SVG Icon&#8217; button, now you can see a new dialog where you can drag your SVG image.</li>
<li>d. Once you update any style, you have to publish the style to see the changes on the map.</li>
<li>e. Note: &#8211; It may take some time to get published and to reflect on the map.</li>
<li>f. It is very easy to publish the changes; you just have to click on the &#8216;Publish&#8217; button on the top-right corner of the map box studio.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-2896 size-full" title="Image" src="https://www.metasyssoftware.com/wp-content/uploads/image-14.png" alt="Image" width="335" height="260" /></li>
<li>g. Now you can see a dialog with a slider where you can see the styles you added.</li>
<li>h. Here you can either ‘Publish as new’ which will replace all the styles, or, use the ‘Publish’ button to add the styles you added in your draft.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-2898 size-full" title="Basic template" src="https://www.metasyssoftware.com/wp-content/uploads/basic-template-15.png" alt="Basic template" width="483" height="440" /></li>
</ul>
<p><strong>6. Steps to add the updated style to our map</strong></p>
<ul>
<li>a. Once the style is published,click on the &#8216;Share&#8217; tab on the top-right corner of the Mapbox Studio. Here you can see a dialog where you can find your &#8216;Your style Url&#8217; and &#8216;Your access token’.<br />
<img loading="lazy" decoding="async" class="alignnone wp-image-2899 size-full" title="Share" src="https://www.metasyssoftware.com/wp-content/uploads/share-16.png" alt="Share" width="564" height="338" /></li>
<li>b. Now update your style URL of the map.
<ul>
<li>i. var map = new mapboxgl.Map({</li>
<li>ii. style: &#8216;Add your style URL Here&#8217;</li>
<li>iii. });</li>
</ul>
</li>
<li>c. Example:
<ul>
<li>i. const feature: feature = {</li>
<li>ii. id: 123,</li>
<li>iii. type: &#8216;Feature&#8217;,</li>
<li>iv. geometry: feature.geometry,</li>
<li>v. properties: {
<ul>
<li>1. meta: feature.meta,</li>
<li>2. icon: &#8216;square-stroke&#8217;</li>
<li>3. // Custom Icon name which is added to the style in Mapbox Studio</li>
</ul>
</li>
<li>vi. }</li>
<li>vii. }</li>
</ul>
</li>
</ul>
<p>We at MetaSys software have helped the clients in building such kind of custom software solutions. For more details &#8211; <a href="https://www.metasyssoftware.com/case-study-react">https://www.metasyssoftware.com/case-study-react</a></p>
</div>The post <a href="https://www.metasyssoftware.com/react/six-smart-steps-to-configure-mapbox-with-reactjs/">Six smart steps to configure Mapbox with ReactJS</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.metasyssoftware.com/react/six-smart-steps-to-configure-mapbox-with-reactjs/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
