<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adyasha Mohanty</title>
    <description>The latest articles on DEV Community by Adyasha Mohanty (@adyasha8105).</description>
    <link>https://dev.to/adyasha8105</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F462704%2F87eebeec-1295-4009-9110-94bd9f471b7a.jpg</url>
      <title>DEV Community: Adyasha Mohanty</title>
      <link>https://dev.to/adyasha8105</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adyasha8105"/>
    <language>en</language>
    <item>
      <title>Season 1: The one where HackerRank discovered Adyasha</title>
      <dc:creator>Adyasha Mohanty</dc:creator>
      <pubDate>Thu, 15 Dec 2022 13:19:52 +0000</pubDate>
      <link>https://dev.to/adyasha8105/season-1-the-one-where-hackerrank-discovered-adyasha-bnc</link>
      <guid>https://dev.to/adyasha8105/season-1-the-one-where-hackerrank-discovered-adyasha-bnc</guid>
      <description>&lt;p&gt;After interning at &lt;strong&gt;HackerRank&lt;/strong&gt; for the past year and a half, writing a blog now seems strange, doesn't it?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;I KNOW!!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So stay tuned for this series, in which I will be releasing the seasons of my &lt;strong&gt;J.O.U.R.N.E.Y at HackerRank&lt;/strong&gt;. And a series without a climax at the end is all a moo point, so hang tight for the final season, y'all!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I hope you get all the F.R.I.E.N.D.S references and if you don't 😳 ... well then I guess you need to go on a &lt;em&gt;BREAK&lt;/em&gt; and binge-watch it. Thank me later!😌 &lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;"So no one told you life was gonna be this way....."&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, the day I received this mail from &lt;a href="https://www.linkedin.com/in/vaasavi-suncol/" rel="noopener noreferrer"&gt;Vassavi&lt;/a&gt;, no one could have told me my life was gonna change this way!&lt;/p&gt;

&lt;p&gt;One hot April afternoon, freshly heartbroken (&lt;em&gt;found out my lobster🦞 wasn’t my lobster at all 💔&lt;/em&gt;), I was cocooned in my bubble when I got this mail from one of the most fun and passionate HR ever. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F87uwqse3nwk71n7zf9se.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F87uwqse3nwk71n7zf9se.png" alt="Mail from HR"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This wasn’t just a mail, it practically rescued me 🥹! I was pumped and started figuring out how to go ahead with this. I approached one of my seniors, &lt;a href="https://www.linkedin.com/in/muskan-khedia/" rel="noopener noreferrer"&gt;Muskan Khedia&lt;/a&gt; who was then an intern at &lt;strong&gt;HackerRank&lt;/strong&gt;. Being the &lt;em&gt;Monica she is&lt;/em&gt;, she helped me with the referral and thus, I answered the mail with my resume and the necessary documents. &lt;/p&gt;

&lt;p&gt;It was all going smoothly. A bit too smooth. And of course, life had to mess up. Yes &lt;del&gt;guys&lt;/del&gt; folks you guessed it right, I got down with Covid 😷 . That day, &lt;em&gt;"it was like there’s rock bottom, 50 feet of crap, then me."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So I got admitted to the hospital, bedridden for two days straight. And as if the universe was testing me, I received a call from Vassavi regarding the interview process. The interview got scheduled while I was still admitted 🤦🏻‍♀️ !&lt;/p&gt;

&lt;p&gt;The only thought in my mind? &lt;strong&gt;If not now, then never&lt;/strong&gt;. I buckled up my mind and started getting ready for the interview that changed my life.&lt;/p&gt;

&lt;p&gt;Okay, enough about the pre-interview overthinking. Let’s talk about the real deal. So after I got enough information regarding the test, my preparation started with exploring what HackerRank is all about. Its &lt;u&gt;core values&lt;/u&gt;, qualities that they look for in their folks, and what exactly was I expected to present to crack it. I went through all the past projects that I was going to showcase, thoroughly understood my role in all my &lt;u&gt;past internships&lt;/u&gt; and polished my &lt;u&gt;React skills&lt;/u&gt; by going through a bunch of articles, quizzes, and blogs.&lt;/p&gt;

&lt;p&gt;But then my brain asked, &lt;strong&gt;&lt;em&gt;Bro what about DSA?!&lt;/em&gt;&lt;/strong&gt; 🤷🏻‍♀️ To disclose the fact, I was quite reluctant for the interview as I felt, HackerRank being synonymous with Data Structures and Algorithms, they might focus a bit more on my DSA knowledge instead of my dev skills.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;But oh boy, &lt;em&gt;could I BE any more wrong!&lt;/em&gt; I got to know, the core requirements for SDE interns at HackerRank were &lt;u&gt;development skills&lt;/u&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbksjkn0l83lbkfz9tdpj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbksjkn0l83lbkfz9tdpj.png" alt="HR is love"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now, with some newly gained confidence, I furnished my dev skills and awaited the interview.&lt;/p&gt;

&lt;p&gt;Well now moving on to the interview….&lt;br&gt;
Should I go on? 🤔 &lt;em&gt;Oh, I wish I could, but I don’t want to.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffisnnaft51fq34zy0vwi.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffisnnaft51fq34zy0vwi.gif" alt="Friends: Oh, I wish I could, but I don’t want to."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To read the whole season go check my &lt;a href="https://adyasha.in/series" rel="noopener noreferrer"&gt;blog&lt;/a&gt;! &lt;/p&gt;

&lt;p&gt;Feel free to connect on &lt;strong&gt;&lt;a href="https://twitter.com/Adyasha8105" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/strong&gt; :)&lt;/p&gt;

</description>
      <category>myjourney</category>
      <category>career</category>
      <category>community</category>
    </item>
    <item>
      <title>A Guide to React Context 💫</title>
      <dc:creator>Adyasha Mohanty</dc:creator>
      <pubDate>Sun, 30 Jan 2022 19:36:15 +0000</pubDate>
      <link>https://dev.to/adyasha8105/a-guide-to-react-context-46oo</link>
      <guid>https://dev.to/adyasha8105/a-guide-to-react-context-46oo</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;What is React Context 🤔?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;React Context&lt;/strong&gt; provides a way to pass data through the component tree without having to pass &lt;code&gt;props&lt;/code&gt; down manually to every level. In React, data is often passed from a parent to its child component as a property.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Context is like a global object to the React component sub-tree 🌐.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What problems does Context solve 😟?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In React applications let parent components pass data long to children components but issues arise when that data is meant to be used by children components multiple layers deep but not by immediate children of that parent component. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's look at the below diagram 📈.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F30n2qtkra29s87j8in7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F30n2qtkra29s87j8in7v.png" alt="Image1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Component A&lt;/code&gt; is clearly the main parent component with immediate children components B, C. These components can receive params from &lt;code&gt;component A&lt;/code&gt; and pass that data to the children components, but what about a scenario where &lt;code&gt;Component E&lt;/code&gt; needs data from &lt;code&gt;Component A&lt;/code&gt; and that data is not needed in &lt;code&gt;Component B&lt;/code&gt; then passing that data to &lt;code&gt;Component B&lt;/code&gt; becomes &lt;em&gt;redundant&lt;/em&gt;. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Props drilling&lt;/em&gt;&lt;/strong&gt;, a term to describe when you pass props down multiple levels to a nested component, through components that don't need it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is the &lt;em&gt;benefit&lt;/em&gt; of React context  - it provides a cool way 😎 of making data readily available to every single child component in the React Application.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;How do we use Context 😕?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As far we get to know that React context allows us to &lt;em&gt;pass down&lt;/em&gt; and use (&lt;em&gt;consume&lt;/em&gt;) data in whatever component we need in our React app without using &lt;code&gt;props&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using the new React Context API depends on &lt;code&gt;four&lt;/code&gt; main steps:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🔸 Create Context using the &lt;code&gt;createContext&lt;/code&gt; method. This function then returns an object with a &lt;strong&gt;Provider&lt;/strong&gt; and a &lt;strong&gt;Consumer&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AuthContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 Next, use the &lt;em&gt;Provider component&lt;/em&gt; to wrap around the parent/main component.&lt;/p&gt;

&lt;p&gt;🔸 Wrap child components in the &lt;em&gt;Provider component&lt;/em&gt; and make it accept a prop called &lt;code&gt;value&lt;/code&gt;. This &lt;code&gt;value&lt;/code&gt; can be anything!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;AuthContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Demo&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/AuthContext.Provider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔸 Use the &lt;em&gt;Consumer component&lt;/em&gt; anywhere below the Provider in the component tree to get a &lt;em&gt;subset&lt;/em&gt; of the state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Demo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;AuthContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Consumer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/AuthContext.Consumer&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📌 &lt;strong&gt;Let's see the full example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AuthContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;AuthContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Happy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Demo&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/AuthContext.Provider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Demo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;AuthContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Consumer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;} /&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;prints&lt;/span&gt; &lt;span class="nx"&gt;happy&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/AuthContext.Consumer&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above our &lt;strong&gt;App component&lt;/strong&gt;, we are creating context with &lt;code&gt;React.createContext()&lt;/code&gt; and putting the result in a variable, &lt;code&gt;AuthContext&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In almost every case, you will want to export it as we are doing here because your component will be in another file. &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that we can pass an initial value to our value prop when we call React.createContext().&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;The created context is an object with two properties: &lt;code&gt;Provider&lt;/code&gt; and &lt;code&gt;Consumer&lt;/code&gt;, both of which are components. &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Things to keep note down what Provider actually do ✍️:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;➡️ It holds &lt;strong&gt;one single javascript&lt;/strong&gt; value that can be anything: an array, a function or an object.&lt;/p&gt;

&lt;p&gt;➡️ It won’t cause its &lt;strong&gt;children to re-render&lt;/strong&gt;: The context’s provider’s direct children won’t re-render every time the provider renders, but the consumers will. &lt;br&gt;
This rule is only valid for re-renders caused by the provider internally &lt;em&gt;(state)&lt;/em&gt;, but if his parent re-renders (props), the provider’s children will re-render as well.&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;All subscribers&lt;/strong&gt; will re-render when the context value changes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In our &lt;em&gt;App component&lt;/em&gt;, we are using AuthContext. Specifically &lt;code&gt;AuthContext.Provider&lt;/code&gt;, To pass our &lt;code&gt;value&lt;/code&gt; down to every component in our App, we wrap our &lt;em&gt;Provider component&lt;/em&gt; around it and in this case, &lt;code&gt;Demo&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On &lt;code&gt;AuthContext.Provider&lt;/code&gt;, we put the value that we want to pass down our entire component tree. We set that equal to the &lt;code&gt;value&lt;/code&gt; prop to do so. (here, &lt;strong&gt;Happy&lt;/strong&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In &lt;code&gt;Demo&lt;/code&gt;, or wherever we want to consume what was provided in our context, we use the &lt;em&gt;consumer component&lt;/em&gt;: &lt;code&gt;AuthContext.Consumer&lt;/code&gt; To use our passed-down value, we use what is called the &lt;strong&gt;render props pattern&lt;/strong&gt;. &lt;br&gt;
It is just a function that the &lt;em&gt;consumer component&lt;/em&gt; gives us as a &lt;code&gt;prop&lt;/code&gt;. And in return for that function, we can return and use that &lt;code&gt;value&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Another way of consuming context with the &lt;strong&gt;useContext hook&lt;/strong&gt;.
&lt;/h4&gt;

&lt;p&gt;📌 Here is the same example using &lt;strong&gt;useContext&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AuthContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;AuthContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Happy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Demo&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/AuthContext.Provider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Demo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AuthContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;;&lt;/span&gt;&lt;span class="err"&gt; 
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;useContext&lt;/strong&gt; accepts the context type as parameter and returns the context value of the nearest provider of that type. If there is no such provider, then the default context value will be returned.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Will app’s performance get impacted 💥?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;🔹 In short, you app’s performance will decrease &lt;em&gt;drastically&lt;/em&gt; if your provider does a lot of work, for example having a value that combines a lot of separate values, you will have a lot of consumers of the same provider, and they will all re-render.&lt;/p&gt;

&lt;p&gt;🔹 When the provider’s wrapper re-renders due to an internal cause (may be state), its children won’t re-render, only a consumer will. It is like your provider’s value teleports from the provider to the consumers directly ignoring everything in between.&lt;/p&gt;

&lt;p&gt;🔹 So, it is more than okay to have multiple contexts and providers.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What differs Redux from context API ?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As you can see, the concepts involved are actually not that different from &lt;strong&gt;Redux&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;So &lt;strong&gt;does context replaces redux?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The answer is &lt;strong&gt;NO&lt;/strong&gt;🙅.&lt;/p&gt;

&lt;p&gt;Redux isn’t only a way to pass down props( teleports them), it allows &lt;em&gt;persistence&lt;/em&gt;, supports &lt;em&gt;middlewares&lt;/em&gt;, and has a lot more advantages.&lt;br&gt;
My recommendation is to use &lt;em&gt;Redux&lt;/em&gt; for complex global state management and &lt;em&gt;Context&lt;/em&gt; for prop drilling.&lt;/p&gt;

&lt;p&gt;As this article isn’t meant to talk about redux, so, I will drop some useful resources to read more about this comparison 👇. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Answer on &lt;a href="https://stackoverflow.com/a/49569183/7104283" rel="noopener noreferrer"&gt;StackOverflow&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Dan’s post about &lt;a href="https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367****" rel="noopener noreferrer"&gt;You Might Not Need Redux&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;In this article, we explored how we can easily use React Context instead of passing down props to share data between components 🚢. &lt;br&gt;
Depending on your use case, you might prefer to use simple &lt;strong&gt;props&lt;/strong&gt;, &lt;strong&gt;React Context&lt;/strong&gt; or even a third-party library like &lt;strong&gt;Redux&lt;/strong&gt; to share data between your components. &lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1483511651890778112-64" src="https://platform.twitter.com/embed/Tweet.html?id=1483511651890778112"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1483511651890778112-64');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1483511651890778112&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;Keep coding 😉. Thank you for reading 💖.&lt;/p&gt;

&lt;p&gt;Feel free to connect on &lt;a href="https://twitter.com/Adyasha8105" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; :)&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to manage API calls in React ⚛️ </title>
      <dc:creator>Adyasha Mohanty</dc:creator>
      <pubDate>Mon, 05 Jul 2021 09:48:46 +0000</pubDate>
      <link>https://dev.to/adyasha8105/how-to-manage-api-calls-in-react-11a8</link>
      <guid>https://dev.to/adyasha8105/how-to-manage-api-calls-in-react-11a8</guid>
      <description>&lt;p&gt;&lt;strong&gt;React library&lt;/strong&gt; is well known for building rich and highly scalable user interfaces. There are many ways to fetch data from an &lt;strong&gt;external API&lt;/strong&gt; in React. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Before you go through this blog be familiar with &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React library&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/API" rel="noopener noreferrer"&gt;Application Programming Interface (API)&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this blog, we will discuss different ways to &lt;em&gt;manage API calls&lt;/em&gt; in React. In the end, you will be able to choose the best approach based on the application requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The Fetch API
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Fetch API&lt;/strong&gt; is built into most modern browsers on the window object (window.fetch) and enables us to make HTTP requests very easily.&lt;/p&gt;

&lt;p&gt;The following code snippets show a simple example of using Fetch API in practice.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// Where we're fetching data from&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://www.abc.cd/test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// We get the API response and receive data in JSON format&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The only goal of this function is to access the data and to convert the response into JSON using the &lt;code&gt;response.json()&lt;/code&gt; method.&lt;br&gt;
Here, the use of the &lt;code&gt;json()&lt;/code&gt; method is to get the response object which is stored in data and used to update the state of users in our application.&lt;/p&gt;

&lt;p&gt;The fact that Fetch is promise-based means we can also catch errors using the &lt;code&gt;.catch()&lt;/code&gt; method. Any error encountered is used as a value to update our error’s state. &lt;/p&gt;

&lt;p&gt;Added to that, we make this request within the &lt;code&gt;useEffect()&lt;/code&gt; hook with an empty dependencies array as the second argument so that our request is only made once, not dependent on any other data.&lt;br&gt;
Here is an example how to use it in &lt;code&gt;useEffect()&lt;/code&gt; hook:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Isn’t this handy! Let’s see what other methods do 😃.&lt;/p&gt;


&lt;h2&gt;
  
  
  2. Axios Library
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Axios&lt;/strong&gt; is a Promise-based HTTP client for JavaScript which can be used in your &lt;em&gt;front-end application&lt;/em&gt; and your &lt;em&gt;Node.js backend&lt;/em&gt;.&lt;br&gt;
By using Axios it’s easy to send asynchronous HTTP requests to REST endpoints and perform &lt;em&gt;CRUD&lt;/em&gt; operations.&lt;/p&gt;

&lt;p&gt;In this example, we have to first install Axios using &lt;em&gt;npm or yarn&lt;/em&gt; and then add it as an import to your parent component.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install axios


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The following code snippets show an example of using Axios:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://www.abc.cd/test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Similar to the &lt;em&gt;Fetch API&lt;/em&gt;, &lt;em&gt;Axios&lt;/em&gt; also returns a &lt;em&gt;promise&lt;/em&gt;. But in Axios, it always returns a JSON response. The coding part is similar to the Fetch API, &lt;em&gt;except for shorter steps&lt;/em&gt; and &lt;em&gt;better error handling&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Check out the &lt;a href="https://axios-http.com/docs/intro" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt; for better knowledge.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  3. Async-Await syntax
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Async/await&lt;/strong&gt; is a relatively new way to write asynchronous code synchronously.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;async&lt;/strong&gt; keyword before a function has two effects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make it always return a promise.&lt;/li&gt;
&lt;li&gt;Allows await to be used in it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;await&lt;/strong&gt; keyword before a promise makes JavaScript wait until that promise settles, and then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If it’s an error, the exception is generated.&lt;/li&gt;
&lt;li&gt;Otherwise, it returns the result.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following is the code snippets :&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://www.abc.cd/test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;When we use &lt;code&gt;useEffect()&lt;/code&gt;, the effect function (the first argument) cannot be made an async function. For that, we can create a separate async function in our component, which we can call synchronously within useEffect and fetch our data accordingly.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  4. Custom React Hook
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;custom Hook&lt;/strong&gt; is a JavaScript function whose name starts with &lt;em&gt;”use”&lt;/em&gt; and that may call other Hooks. The idea behind custom hooks is to extract component logic into reusable functions.&lt;/p&gt;

&lt;p&gt;So let's call our custom hook: &lt;code&gt;useFetch&lt;/code&gt;. This hook accepts two arguments, the &lt;em&gt;URL&lt;/em&gt; we need to query to fetch the data and an object representing the &lt;em&gt;options&lt;/em&gt; we want to apply to the request.&lt;/p&gt;

&lt;p&gt;Alright! Now, let's see how easy it is to fetch data with our &lt;code&gt;useEffect()&lt;/code&gt; hook. We are going to use the Fetch API to make our request. For that, we have to pass the URL and the options we want to retrieve. From there, we get an object that we can use to render our application.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useFetch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://www.abc.cd/test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;useFetch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We can call whenever we need to fetch data inside our application.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;useFetch&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./useFetch&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useFetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://www.abc.cd/test&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  5. React Query Library
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;React-query&lt;/strong&gt; is a great library that solves the problem of managing server state and caching in applications. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"It makes fetching, caching, synchronizing, and updating server state in your React applications a breeze”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Firstly, let’s install the required package&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install react-query react-query-devtools


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: React Query also has its own &lt;a href="https://react-query.tanstack.com/devtools" rel="noopener noreferrer"&gt;dev tools&lt;/a&gt; which help us to visualize the inner workings of React Query.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;React-query&lt;/em&gt; gives us a cache, which you can see below through the React Query Devtools. This enables us to easily manage the requests that we have made according to the key value that we specify for each request.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;QueryClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;QueryClientProvider&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useQuery&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-query&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ReactQueryDevtools&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-query/devtools&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;queryClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;QueryClient&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;QueryClientProvider&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;queryClient&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;FetchData&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/QueryClientProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;FetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;UserData&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://www.abc.cd/test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="c1"&gt;// data you want to show&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ReactQueryDevtools&lt;/span&gt; &lt;span class="nx"&gt;initialIsOpen&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rootElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rootElement&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;In short, we just need to tell the library where you need to fetch the data, and it will handle caching, background updates, and refresh data without any extra code or configuration.&lt;/p&gt;

&lt;p&gt;It also provides some hooks or events for mutation and queries to handle errors and other states of side effects which remove the need for &lt;code&gt;useState()&lt;/code&gt; and &lt;code&gt;useEffect()&lt;/code&gt; hooks and replaces them with a few lines of React Query logic.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For better insights check out the &lt;a href="https://react-query.tanstack.com/quick-start" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are various other ways to manage data fetching such as &lt;a href="https://swr.vercel.app/" rel="noopener noreferrer"&gt;&lt;em&gt;SWR&lt;/em&gt;&lt;/a&gt;, &lt;a href="https://graphql.org/" rel="noopener noreferrer"&gt;&lt;em&gt;GraphQL API&lt;/em&gt;&lt;/a&gt;, but this blog post is not actually  explaining them in depth but you can check it out :)&lt;/p&gt;



&lt;p&gt;That's all about it. By the way don't forget to check out the comment section of the following tweet. This might help you to choose the best approach.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1347978564251963392-899" src="https://platform.twitter.com/embed/Tweet.html?id=1347978564251963392"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1347978564251963392-899');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1347978564251963392&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy coding 😉&lt;/strong&gt;. Thank you for reading my blog 💖. &lt;/p&gt;

&lt;p&gt;Feel free to connect on &lt;strong&gt;&lt;a href="https://twitter.com/Adyasha8105" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/strong&gt; :) &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/Adyasha8105" rel="noopener noreferrer"&gt;&lt;br&gt;
 &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fpracticaldev%2Fimage%2Ffetch%2Fs--8vsiOGpo--%2Fc_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880%2Fhttps%3A%2F%2Fgithub.com%2Fappcraftstudio%2Fbuymeacoffee%2Fraw%2Fmaster%2FImages%2Fsnapshot-bmc-button.png"&gt;&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why you should use Chakra UI ⚡️ ?</title>
      <dc:creator>Adyasha Mohanty</dc:creator>
      <pubDate>Wed, 02 Jun 2021 14:46:33 +0000</pubDate>
      <link>https://dev.to/adyasha8105/why-you-should-use-chakra-ui-bg5</link>
      <guid>https://dev.to/adyasha8105/why-you-should-use-chakra-ui-bg5</guid>
      <description>&lt;p&gt;Before beginning coding one significant question sprung up always: &lt;em&gt;“Which library would it be a good idea to style the components?”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I’ve worked on various libraries such as &lt;em&gt;Bootstrap, Material UI or styled-components&lt;/em&gt;. And you may be thinking why you need another UI library when you already have a big alternative.&lt;br&gt;
Recently, &lt;em&gt;Chakra UI ⚡️&lt;/em&gt; has gained a lot of attraction because of its &lt;em&gt;accessibility&lt;/em&gt; and &lt;em&gt;high customization&lt;/em&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Installation⚙️
&lt;/h3&gt;

&lt;p&gt;Chakra UI can be installed via NPM/Yarn.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// If you are using npm:
$ npm i @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^4

// or, using Yarn:
$ yarn add @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the packages are installed, a provider needs to be configured.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ChakraProvider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@chakra-ui/react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyApp&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pageProps&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ChakraProvider&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;pageProps&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ChakraProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;MyApp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Benefits of Chakra UI 📖
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Simpler Components&lt;/em&gt; : The best feature of Chakra UI is how components are designed to be small so that you can compose them together. You can build bigger elements easily by arranging them the same as HTML tags.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's look here: &lt;code&gt;Box&lt;/code&gt; and &lt;code&gt;Text&lt;/code&gt; are the most basic components just like &lt;code&gt;div&lt;/code&gt; and &lt;code&gt;p&lt;/code&gt; tags respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Header&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Box&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;base&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;70%&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;sm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;50%&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;md&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;40%&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Adyasha&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Text&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;me&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Box&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Header&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't forgot to import the components: &lt;code&gt;Header&lt;/code&gt;, &lt;code&gt;Box&lt;/code&gt;, &lt;code&gt;Text&lt;/code&gt; from &lt;em&gt;@chakra-ui/react&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: For better sight, you can check the &lt;a href="https://chakra-ui.com/docs/getting-started" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;, there you can see plenty of components which will be enough for building your project.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Easy to theme and customize&lt;/em&gt; : One of the advantages of Chakra UI is that you can easily adjust it to your design needs. Inside the styles folder, Create a &lt;em&gt;theme.js&lt;/em&gt; file. You can specify things like font-family, font-sizes, colors, breakpoints, etc.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;extendTheme&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@chakra-ui/react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;customtheme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;extendTheme&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;variants&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="na"&gt;fontSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;4xl&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fontWeight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bold&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="na"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="na"&gt;fontSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2xl&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fontWeight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;semibold&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;customtheme&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Dark mode support&lt;/em&gt; : By default, most of Chakra's components are dark mode compatible. A little bit of change in &lt;code&gt;theme config&lt;/code&gt; and you are good to go ✈︎&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FNnN3l2m.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FNnN3l2m.gif" alt="GIF"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: In some cases, when you switch to dark mode and refresh the page, you might experience a quick flash of white mode before it switches correctly and they're looking to fix it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Responsive styles&lt;/em&gt; : Chakra UI supports &lt;em&gt;responsive styles out of the box&lt;/em&gt;. To add them, we can set default breakpoints or you can create your own.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createBreakpoints&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@chakra-ui/theme-tools&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;breakpoints&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createBreakpoints&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;sm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;30em&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;md&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;48em&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;lg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;62em&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;xl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;80em&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2xl&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;96em&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use these breakpoints to resize your &lt;code&gt;box&lt;/code&gt; or &lt;code&gt;div&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Box&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;&lt;span class="na"&gt;sm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;200px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;md&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;400px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;xl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;600px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;Me&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fully&lt;/span&gt; &lt;span class="nx"&gt;responsive&lt;/span&gt; &lt;span class="p"&gt;:)&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Box&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Preview 👀:
&lt;/h3&gt;

&lt;p&gt;I built a simple project or you can say just a &lt;a href="https://chakra-ui-next-js.vercel.app/" rel="noopener noreferrer"&gt;landing page&lt;/a&gt; with &lt;em&gt;NextJS&lt;/em&gt; and &lt;em&gt;Chakra UI&lt;/em&gt; and the reason behind this project is to learn more about the features of Chakra UI and it was by far the easiest component library I’ve tried so far.&lt;/p&gt;

&lt;p&gt;Take a sneak peek:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F54095539%2F120494197-3cc82000-c3d9-11eb-90ee-06625da641db.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F54095539%2F120494197-3cc82000-c3d9-11eb-90ee-06625da641db.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is all only a little model I think if you want to cover all the customisation of this library go check the &lt;a href="https://chakra-ui.com/docs/getting-started" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  📍 Conclusion:
&lt;/h2&gt;

&lt;p&gt;As a promising new library, it is constantly improving and the hype is building around the library. More components will probably be added soon. So you can consider using it for your next React project :D&lt;/p&gt;

&lt;p&gt;I share what I think on &lt;a href="https://twitter.com/Adyasha8105" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;💙. This post is also posted on my &lt;a href="https://www.adyablogs.tech/blogs/Why-you-should-use-Chakra-UI-!" rel="noopener noreferrer"&gt;blog&lt;/a&gt; page.&lt;/p&gt;

&lt;h2&gt;
  
  
  🙌 Support me:
&lt;/h2&gt;

&lt;p&gt;My projects are fueled by coffees ☕, get one for me!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/Adyasha8105" rel="noopener noreferrer"&gt;&lt;br&gt;
 &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fpracticaldev%2Fimage%2Ffetch%2Fs--8vsiOGpo--%2Fc_limit%252Cf_auto%252Cfl_progressive%252Cq_auto%252Cw_880%2Fhttps%3A%2F%2Fgithub.com%2Fappcraftstudio%2Fbuymeacoffee%2Fraw%2Fmaster%2FImages%2Fsnapshot-bmc-button.png"&gt;&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

</description>
      <category>chakraui</category>
      <category>react</category>
      <category>nextjs</category>
      <category>css</category>
    </item>
    <item>
      <title>React-Notifications ⚠️</title>
      <dc:creator>Adyasha Mohanty</dc:creator>
      <pubDate>Tue, 20 Apr 2021 11:21:57 +0000</pubDate>
      <link>https://dev.to/adyasha8105/react-notifications-33do</link>
      <guid>https://dev.to/adyasha8105/react-notifications-33do</guid>
      <description>&lt;p&gt;Here I’ll show how we can handle notifications in our React project. First, we’ll be using &lt;strong&gt;react-notifications&lt;/strong&gt;🔔, which, as its name suggests, is a notification component for React.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation:
&lt;/h2&gt;

&lt;p&gt;Go to the client &lt;em&gt;project directory&lt;/em&gt; and install the following npm package:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --save react-notifications&lt;/code&gt;&lt;br&gt;
    or&lt;br&gt;
 &lt;code&gt;yarn add react-notifications&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting up the Notification container:
&lt;/h2&gt;

&lt;p&gt;Now update the &lt;em&gt;App.js&lt;/em&gt; file. Import &lt;em&gt;NotificationContainer&lt;/em&gt; from react-notifications and the &lt;em&gt;notifications.css&lt;/em&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="c1"&gt;// React Notification&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-notifications/lib/notifications.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;NotificationContainer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-notifications&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
 &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="p"&gt;...&lt;/span&gt;
   &lt;span class="p"&gt;...&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;NotificationContainer&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Router&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far, we have completed our setup for &lt;em&gt;NotificationContainer&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: Use only one NotificationContainer component in the app.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now it’s time to pass notifications from different components to display their message.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Notifications from components:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// React Notification&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;NotificationManager&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-notifications&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Add this line where you want to show the notification&lt;/span&gt;
&lt;span class="nx"&gt;NotificationManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hey I am Adyasha&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Info!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Horray, you did it. Now you can run your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Available NotificationManager APIs:
&lt;/h2&gt;

&lt;p&gt;You can apply this same method to different components in your project. Notifications will be displayed in different colors depending on the notification type.&lt;br&gt;
For this package, there are four different APIs available to us of the following types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;info&lt;/li&gt;
&lt;li&gt;success&lt;/li&gt;
&lt;li&gt;warning&lt;/li&gt;
&lt;li&gt;error&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://camo.githubusercontent.com/5552056a6a08decb8c056714ddb5f14cdde85cf998c81e2d6c8693b363923ede/68747470733a2f2f6465762d746f2d75706c6f6164732e73332e616d617a6f6e6177732e636f6d2f692f63327a6235743430776872376f327233366561672e706e67" class="article-body-image-wrapper"&gt;&lt;img src="https://camo.githubusercontent.com/5552056a6a08decb8c056714ddb5f14cdde85cf998c81e2d6c8693b363923ede/68747470733a2f2f6465762d746f2d75706c6f6164732e73332e616d617a6f6e6177732e636f6d2f692f63327a6235743430776872376f327233366561672e706e67" alt="Image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s an example for the &lt;em&gt;success&lt;/em&gt; type — simply replace &lt;em&gt;success&lt;/em&gt; with the proper notification type for the given situation :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;NotificationManager.success(message, title, timeOut, callback, priority);&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can also pass five different parameters along with the message: &lt;em&gt;message&lt;/em&gt;, &lt;em&gt;title&lt;/em&gt;, &lt;em&gt;timeOut&lt;/em&gt;, &lt;em&gt;callback&lt;/em&gt;, and &lt;em&gt;priority&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The parameters that follow the notification type are described below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;message&lt;/em&gt;: The message we want to pass. It has to be a string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;title&lt;/em&gt;: The title of the notification. Again, its type is a string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;timeOut&lt;/em&gt;: The popup timeout in milliseconds. This has to be an integer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;callback&lt;/em&gt;: We can pass a function (type; function) through the notification. It executes after the popup is called.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;priority&lt;/em&gt;: This is a boolean parameter. We can push any notification to the top at any point by setting the priority to true.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's all. Thanks for your patience ❤️! Have a nice day ;)&lt;/p&gt;

&lt;p&gt;Find me on Twitter &lt;a href="https://twitter.com/Adyasha8105"&gt;@Adyasha8105&lt;/a&gt;👀.&lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Using Font Awesome 5 🏳️ in React</title>
      <dc:creator>Adyasha Mohanty</dc:creator>
      <pubDate>Tue, 16 Feb 2021 09:53:27 +0000</pubDate>
      <link>https://dev.to/adyasha8105/using-font-awesome-5-in-react-3j8j</link>
      <guid>https://dev.to/adyasha8105/using-font-awesome-5-in-react-3j8j</guid>
      <description>&lt;p&gt;The &lt;a href="https://fontawesome.com/how-to-use/on-the-web/using-with/react" rel="noopener noreferrer"&gt;Font Awesome&lt;/a&gt; went all out with new version 5 adding a wide variety of SVG icons and providing users with new features🤩.&lt;/p&gt;

&lt;p&gt;If you’ve worked with Font Awesome in the past, something like &lt;code&gt;fa-profile&lt;/code&gt; might look familiar. Font Awesome introduced icon styles like &lt;code&gt;fas&lt;/code&gt; for Font Awesome solid, &lt;code&gt;fal&lt;/code&gt; for Font Awesome Light, etc. This adds a great deal of flexibility for UI/UX design.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F54095539%2F108038643-1916df00-7061-11eb-8c97-698af453e2d8.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F54095539%2F108038643-1916df00-7061-11eb-8c97-698af453e2d8.PNG" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moreover, there are Font Awesome packages (like the one we're going to use!) for &lt;em&gt;React&lt;/em&gt;, Angular, and Vue 😮.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;To get started, we’re going to install &lt;code&gt;react-fontawesome&lt;/code&gt; along with their libraries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// If you are using npm:
$ npm install @fortawesome/react-fontawesome @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons

// or, using Yarn:
$ yarn add @fortawesome/react-fontawesome @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;em&gt;The packages we're introducing just contain the free version 🆓. If you’re looking to utilize new _pro icons&lt;/em&gt; and styles, look at their &lt;a href="https://fontawesome.com/how-to-use/on-the-web/using-with/react" rel="noopener noreferrer"&gt;site&lt;/a&gt; for additional installation and setup directions._&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F54095539%2F108038981-7f9bfd00-7061-11eb-8995-8ab1feb3642d.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F54095539%2F108038981-7f9bfd00-7061-11eb-8995-8ab1feb3642d.PNG" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Let's move forward to implement these beautiful icons 👌 throughout our app.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;em&gt;There are numerous approaches to utilize these symbols however we will going to focus on building a library to effortlessly get to all symbols.&lt;/em&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The following code to add icons to the library can be done at a root level of our application i.e &lt;code&gt;App.js&lt;/code&gt;. We’ll start by importing the required files and calling &lt;code&gt;fontawesome-svg-core&lt;/code&gt;’s &lt;code&gt;library.add&lt;/code&gt; to pull our icons.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//App.js&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;library&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@fortawesome/fontawesome-svg-core&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;faCheckSquare&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;faMugHot&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@fortawesome/free-solid-svg-icons&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;library&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;faCheckSquare&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;faMugHot&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;All icons can be found in &lt;a href="https://fontawesome.com/icons?d=gallery&amp;amp;m=free" rel="noopener noreferrer"&gt;Font Awesome’s icon library&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We have successfully added the icons we need. Now it's time to implement it in our component 👍.&lt;br&gt;
Imagine that we have a component called &lt;code&gt;Icon.js&lt;/code&gt;. Since they are already been added to our library in &lt;code&gt;App.js&lt;/code&gt; we just need to import this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Icon.js&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;FontAwesomeIcon&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@fortawesome/react-fontawesome&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Drink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;FontAwesomeIcon&lt;/span&gt; &lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;check-square&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
       &lt;span class="nx"&gt;Drink&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;FontAwesomeIcon&lt;/span&gt; &lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mug-hot&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By adding &lt;code&gt;faCheckSquare&lt;/code&gt; and &lt;code&gt;faMugHot&lt;/code&gt; to the library, we can refer to them throughout the app using their icon string names &lt;code&gt;check-square&lt;/code&gt; and &lt;code&gt;mug-hot&lt;/code&gt; (in lowercase letters).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F54095539%2F108039796-955df200-7062-11eb-83cc-cd1379795466.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F54095539%2F108039796-955df200-7062-11eb-83cc-cd1379795466.PNG" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wait 🤔, I think our icons and text are a little squished and, might I venture to say, boring, so let’s add a space between the icon and the text and change the icon’s color and size :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;FontAwesomeIcon&lt;/span&gt; &lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;check-square&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nl"&gt;Drink&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;FontAwesomeIcon&lt;/span&gt; &lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mug-hot&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pink&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2x&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, the &lt;em&gt;FontAwesomeIcon&lt;/em&gt; component can take a few different props to change the icon style. Here we used the &lt;code&gt;color&lt;/code&gt; and &lt;code&gt;size&lt;/code&gt; props. The size prop expects a string value like &lt;code&gt;xs&lt;/code&gt;, &lt;code&gt;lg&lt;/code&gt;, &lt;code&gt;2x&lt;/code&gt;, &lt;code&gt;3x&lt;/code&gt; and so on 😃. &lt;br&gt;
There are quite a few more props that can be passed-in. Notably, the &lt;code&gt;rotation&lt;/code&gt; and &lt;code&gt;pulse&lt;/code&gt; boolean props will have the icon rotate on itself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F54095539%2F108039940-bb839200-7062-11eb-8e03-a6d38e23e11a.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F54095539%2F108039940-bb839200-7062-11eb-8e03-a6d38e23e11a.PNG" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;em&gt;Note: Don't use the CDN link of FontAwesome in your &lt;code&gt;index.html&lt;/code&gt; file. It will decrease the performance of your site.&lt;/em&gt;&lt;/em&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That's all. Hurray🎉, you did it. The process is pretty straight-forward but you can easily implement this in your app. Do give it a try, you will definitely love it 😍. &lt;/p&gt;

&lt;p&gt;Thanks for Reading! Have a great day :)&lt;/p&gt;

&lt;p&gt;Find me on Twitter  &lt;a href="https://twitter.com/Adyasha8105" rel="noopener noreferrer"&gt;@Adyasha8105&lt;/a&gt;👀.&lt;br&gt;
This post is also posted on my &lt;a href="https://www.adyablogs.tech/blogs/Using-Font-Awesome-5-in-React" rel="noopener noreferrer"&gt;blog&lt;/a&gt; page.&lt;/p&gt;

</description>
      <category>react</category>
      <category>fontawesome</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Intro to Styled-Components
💅...</title>
      <dc:creator>Adyasha Mohanty</dc:creator>
      <pubDate>Wed, 03 Feb 2021 16:09:03 +0000</pubDate>
      <link>https://dev.to/adyasha8105/intro-to-styled-components-2pa1</link>
      <guid>https://dev.to/adyasha8105/intro-to-styled-components-2pa1</guid>
      <description>&lt;p&gt;&lt;strong&gt;Styled-Components&lt;/strong&gt;💅 is the leading framework in &lt;em&gt;CSS-in-JS&lt;/em&gt; libraries all over the world. They are easy to integrate into existing applications that are using other methods of styling. &lt;br&gt;
By focusing on a single use case we managed to optimize the experience for developers as well as the output for end users.&lt;/p&gt;

&lt;p&gt;The main reason for this popularity is that: finally, we can use the &lt;em&gt;power of JavaScript inside our stylesheets&lt;/em&gt;💪.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2F1.bp.blogspot.com%2F-0jHs8Romdfg%2FV7HGqMg7jlI%2FAAAAAAAACMY%2FTZSgdvjPLTEVGHpwqAISstf8k_RDKOsOwCEw%2Fs1600%2520bruce-almighty-ive-got-the-power-01.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2F1.bp.blogspot.com%2F-0jHs8Romdfg%2FV7HGqMg7jlI%2FAAAAAAAACMY%2FTZSgdvjPLTEVGHpwqAISstf8k_RDKOsOwCEw%2Fs1600%2520bruce-almighty-ive-got-the-power-01.gif" alt="power"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The easiest way we can modify styles with JavaScript is using inline styles. It is not super efficient and even elegant, but it is absolutely legal and the greatest benefit of this technique is that the styles will be encapsulated in the scope of the component. &lt;/p&gt;

&lt;p&gt;React supports inline styles from the beginning of its existence so it can be a way of creating styles in &lt;a href="https://reactjs.org/docs/getting-started.html" rel="noopener noreferrer"&gt;React applications⚛️&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Note: Styled components are available both for React and React Native, and while you should definitely check out the React Native guide, our focus here will be on styled-components for React.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Installation⚙️
&lt;/h2&gt;

&lt;p&gt;Styled-Components can be installed via NPM like almost everything else you need to develop with React.js.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i styled-components&lt;/code&gt;&lt;br&gt;
    or&lt;br&gt;
 &lt;code&gt;yarn add styled-components&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Starting Out🏃
&lt;/h2&gt;

&lt;p&gt;Then you can import the library into React.js, and create our first styled component. Put these simple lines in your react code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;styled-components&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Styled component named StyledButton&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;StyledButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="s2"&gt;`
  background-color: black;
  color: red;
  font-size: 15px;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;OurFirstComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// any other component&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;StyledButton&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Login&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/StyledButton&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;vscode-styled-components&lt;/em&gt; is a great extension for VS Code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First of all, you have to import the &lt;code&gt;styled&lt;/code&gt; function from &lt;em&gt;styled-components&lt;/em&gt; package and after that, you can choose from the predefined set of HTML tags (the library supports them all) an interesting component to use.&lt;/p&gt;

&lt;p&gt;The part of the code after the import statement looks like function invocation but here we have &lt;em&gt;&lt;em&gt;backticks&lt;/em&gt;&lt;/em&gt; 😮instead of brackets. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;styled-components use one of the newest features from the_ES6 standard_ of JavaScript called &lt;em&gt;&lt;em&gt;tagged template literals&lt;/em&gt;&lt;/em&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So basically the code between &lt;em&gt;backticks&lt;/em&gt; is a body of the button function. &lt;br&gt;
Isn’t it look familiar 👀? Well, it should, because this is a regular CSS code with regular CSS syntax. &lt;/p&gt;

&lt;p&gt;In raw HTML and CSS, we would have this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;button {
  background-color: black;
  color: red;
  font-size: 15px;
}

&amp;lt;button&amp;gt; Login &amp;lt;/button&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;em&gt;In short🤏: StyledButton is the styled component, and it will be rendered as an HTML button with the contained styles. styled is an internal utility method that transforms the styling from JavaScript into actual CSS.&lt;/em&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And that is all! Incredibly easy to start with if you know CSS 😃. Let’s move further👉.&lt;/p&gt;

&lt;h2&gt;
  
  
  Passing props😉
&lt;/h2&gt;

&lt;p&gt;Styled components are &lt;em&gt;functional&lt;/em&gt;, so you can easily style elements dynamically. &lt;br&gt;
Imagine you have two types of buttons on your page having different background colors and you are not allowed to make two different styled-components. Then What should you do 🤔? &lt;/p&gt;

&lt;p&gt;In this case, we can adapt their styling based on their props. We can pass additional properties into a styled component in the same way you pass them in other React components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;styled-components&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;StyledButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="s2"&gt;`
  border: none;
  min-width: 300px;
  font-size: 15px;
  padding: 6px 8px;
  /* the resulting background color will be based on these props */
  background-color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bg&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;black&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;black&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="s2"&gt;`;

function BackgroundComponent() {
  return (
    &amp;lt;div&amp;gt;
      // Use of different props
      &amp;lt;StyledButton bg="black"&amp;gt; Button1 &amp;lt;/StyledButton&amp;gt;
      &amp;lt;StyledButton bg="red"&amp;gt; Button2 &amp;lt;/StyledButton&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;StyledButton&lt;/code&gt; is a React component that accepts props, we can assign a different background color based on the existence or value of the &lt;code&gt;bg prop&lt;/code&gt;. Isn't it cool 😎? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fwww.theboobgeek.com%2Fwp-content%2Fuploads%2F2014%2F11%2FIm-Cool-gif.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Fwww.theboobgeek.com%2Fwp-content%2Fuploads%2F2014%2F11%2FIm-Cool-gif.gif" alt="Cool Image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  More Features✍️
&lt;/h2&gt;

&lt;p&gt;The examples which I presented are really simple and basic, but &lt;em&gt;styled-components&lt;/em&gt; has more useful features including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Theming&lt;/em&gt; – Styled-components provides theming capabilities and enables you to support multiple looks and feels.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Nested rules&lt;/em&gt; – If you are familiar with SASS or LESS preprocessor you know how nesting rules can be useful. With styled-components, it is possible too.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Scoped selectors&lt;/em&gt; – You don’t have to think about naming conventions to avoid selector collisions on your pages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Dead code elimination&lt;/em&gt; – Styled-components has an optional configuration to remove code that does not affect the program results.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Global Styling&lt;/em&gt; - The styled-components framework also enables you to create global styles to be applied to all styled-components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Server-side rendering support&lt;/em&gt; – By using ServerStyleSheet object and StyleSheetManager you can utilize all styles from the client-side and returns them from the server-side.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Stylelint support&lt;/em&gt; – Good real-time linting is priceless when you have to debug your styles.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Use with other CSS frameworks&lt;/em&gt; – You can use styled-components with any CSS framework like Material Design styled component.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you can see, there are a lot of features that you can use while working with &lt;em&gt;styled-components&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For more Information, the &lt;a href="https://styled-components.com/docs/basics" rel="noopener noreferrer"&gt;styled-components documentation&lt;/a&gt; is always a good place to go.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The idea behind styled-components can be really weird at the beginning of your journey but if you give it a try, you will love it 😍. &lt;/p&gt;

&lt;p&gt;Thanks for Reading💙! Have a great day :)&lt;/p&gt;

&lt;p&gt;Find me on Twitter &lt;a href="https://twitter.com/Adyasha8105" rel="noopener noreferrer"&gt;@Adyasha805&lt;/a&gt;.&lt;br&gt;
This post is also posted on my &lt;a href="https://www.adyablogs.tech/blogs/Intro-to-Styled-Components" rel="noopener noreferrer"&gt;blog&lt;/a&gt; page.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>styledcomponents</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My journey to the Open-source world</title>
      <dc:creator>Adyasha Mohanty</dc:creator>
      <pubDate>Thu, 03 Sep 2020 08:00:47 +0000</pubDate>
      <link>https://dev.to/adyasha8105/my-journey-to-the-open-source-world-4504</link>
      <guid>https://dev.to/adyasha8105/my-journey-to-the-open-source-world-4504</guid>
      <description>&lt;p&gt;&lt;strong&gt;GSSoC’20: Beginning of a new journey&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I was always interested in Open Source contribution from long back but was not able to start as I felt it’s not much beginner-friendly. I started searching about how to get started with it and finally landed up to &lt;strong&gt;GirlsScript Summer of Code&lt;/strong&gt;. I read all about it and I was highly exuberant and applied for it immediately. I was extremely happy and pumped when I received that I am shortlisted for the same🎉.&lt;/p&gt;

&lt;p&gt;And thus started, the 3 months-long journeys of my contribution to GSSoC’ 20 on 1st March 2020. There were various projects based on different skills and every participant is free to claim any project. Even one can contribute to multiple projects as per their choice. There was so much ambiguity in my mind as there were so many projects to chose from. I ended up taking some projects.&lt;/p&gt;

&lt;p&gt;My First Contribution was to a project named as &lt;a href="https://github.com/vinitshahdeo/Water-Monitoring-System"&gt;&lt;strong&gt;Water Monitoring System&lt;/strong&gt;&lt;/a&gt; as the initial issues in that project were quite beginner-friendly. It was initially difficult getting used to the environment (Fixing the merge conflicts and much more) as I was very unfamiliar with git and all the projects which were on GitHub, so I followed some &lt;a href="https://www.youtube.com/watch?v=dnGeRjP8oxw"&gt;youtube videos&lt;/a&gt; and &lt;a href="https://product.hubspot.com/blog/git-and-github-tutorial-for-beginners"&gt;read blogs&lt;/a&gt; and also with the help of my sister, it became a piece of cake😎.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;There are many things that seem impossible only so long as one does not attempt them.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Then after some contribution, I landed up into another project which is &lt;a href="https://github.com/CropAi/Frontend"&gt;&lt;strong&gt;Crop AI&lt;/strong&gt;&lt;/a&gt; (Frontend). My experience here was amazing. I got to learn about various tech stacks like HTML, CSS, Javascript in-depth, and also about UX/UI designing.&lt;/p&gt;

&lt;p&gt;After the frontend part in Crop AI was over, I got interested in another project named &lt;a href="https://github.com/smaranjitghose/girlscript_chennai_website"&gt;&lt;strong&gt;Girscript Boilerplate Website&lt;/strong&gt;&lt;/a&gt;. Here I built my skill set even more. It was during the contribution to the documentation of this project, I got to learn about &lt;a href="https://www.sphinx-doc.org/en/master/internals/contributing.html"&gt;&lt;em&gt;Sphinx&lt;/em&gt;&lt;/a&gt; which taught me a lot 😊. Once I figured out how things operate, it was fairly straightforward to work with and I started taking up a variety of challenging issues and bugs to solve and secured a spot as the top contributor of the project (edited).&lt;/p&gt;

&lt;p&gt;Like initially I had no idea about UX/UI designing. After taking some design issues, for example, the landing page of the Water Monitoring System, the logos for the Crop AI project( you can see my logos present in the project both in frontend and backend part), the logo for the Girscript Boilerplate Website, and also the whole promotional website for the Girlscript_app present in Girscript Boilerplate Website and many more, I have added a new skill into my skill set😃. And now I am so fascinated with this field that I don’t mind spending my whole day working on the design, checking other people's work on &lt;em&gt;Behance&lt;/em&gt;, &lt;em&gt;Dribbble&lt;/em&gt;, etc.&lt;/p&gt;

&lt;p&gt;Apart from all these projects, I also have made few contributions to some other projects like &lt;a href="https://github.com/Techtonica/curriculum"&gt;Technotica Curriculum&lt;/a&gt;, &lt;a href="https://github.com/CropAi"&gt;Crop AI&lt;/a&gt; (Backend &amp;amp; Android-application), &lt;a href="https://github.com/sharmaaditya570191/BossY"&gt;BossY&lt;/a&gt;, &lt;a href="https://github.com/Ignitus/Ignitus-client"&gt;Ignitus Client&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It almost feels like yesterday that I started my contribution. My journey with GSSoC has motivated me to explore more of the open-source world! I would like to thank the &lt;a href="https://www.gssoc.tech/"&gt;&lt;strong&gt;GirlScript Summer of Code&lt;/strong&gt;&lt;/a&gt; and the &lt;a href="https://www.girlscript.tech/home"&gt;&lt;strong&gt;GirlScript Foundation&lt;/strong&gt;&lt;/a&gt; for this incredible opportunity, along with my mentors who have always been supportive and encouraged me to keep learning.&lt;/p&gt;

&lt;p&gt;Looking forward to taking a deeper dive into the Open Source world from now onwards🙌.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;By the way, I just forgot to add that if you observe my GitHub, &lt;a href="https://github.com/Adyasha8105"&gt;Adyasha Mohanty&lt;/a&gt; then there is a big change starting from one to 521 contributions that make me proud of my journey so far.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading till the end. Keep Contributing!&lt;/p&gt;

&lt;p&gt;Feel free to get in touch with me over &lt;a href="https://www.linkedin.com/in/adyasha-mohanty-7a6254191/"&gt;Linkedin&lt;/a&gt;, &lt;a href="https://twitter.com/_Adyasha8105_"&gt;Twitter&lt;/a&gt;, or simply drop me an email at &lt;a href="mailto:adyashamohanty8105@gmail.com"&gt;adyashamohanty8105@gmail.com&lt;/a&gt;😇.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>github</category>
      <category>gssoc20</category>
    </item>
  </channel>
</rss>
