<?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: kapeel kokane</title>
    <description>The latest articles on DEV Community by kapeel kokane (@kokaneka).</description>
    <link>https://dev.to/kokaneka</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%2F185874%2Fe587dd79-ed59-41d0-8fe8-50b345cb7c2b.jpeg</url>
      <title>DEV Community: kapeel kokane</title>
      <link>https://dev.to/kokaneka</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kokaneka"/>
    <language>en</language>
    <item>
      <title>useReducer() hook - Redux inside your component</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Fri, 14 Jul 2023 17:53:03 +0000</pubDate>
      <link>https://dev.to/kokaneka/usereducer-hook-redux-inside-your-component-3dha</link>
      <guid>https://dev.to/kokaneka/usereducer-hook-redux-inside-your-component-3dha</guid>
      <description>&lt;p&gt;Hey There 👋🏾&lt;/p&gt;

&lt;p&gt;Welcome to another post in the &lt;strong&gt;React demystified&lt;/strong&gt; series. &lt;/p&gt;

&lt;p&gt;Last week, we dug deep into the concept of &lt;code&gt;Context&lt;/code&gt; in React👇🏾&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/kokaneka" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XERE2L0Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--itHkFn_r--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/185874/e587dd79-ed59-41d0-8fe8-50b345cb7c2b.jpeg" alt="kokaneka"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/kokaneka/mastering-reacts-context-a-guide-to-efficient-state-propagation-4804" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Mastering React's Context: A Guide to Efficient State Propagation&lt;/h2&gt;
      &lt;h3&gt;kapeel kokane ・ Jul 9&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;This week, we look into &lt;code&gt;useReducer&lt;/code&gt;. Let's do it 🙌🏾&lt;/p&gt;




&lt;h3&gt;
  
  
  Use case for useReducer
&lt;/h3&gt;

&lt;p&gt;Let us try to explore the use cases where we would think about using the &lt;code&gt;useReducer&lt;/code&gt; hook. &lt;br&gt;
Before that, let us start off with a simple example. If we had to write the code for a simple component that holds a &lt;strong&gt;count&lt;/strong&gt; as state, here's how we would write it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above initialises the state to 0. We also have &lt;strong&gt;count&lt;/strong&gt; through which we can access the current value of the state and &lt;code&gt;setCount&lt;/code&gt; through which we can set a value of the state. &lt;/p&gt;

&lt;p&gt;If we need to set the value of the state, it's quite straight forward, we call &lt;code&gt;setCount&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But, what if we want to perform several operations on the state?&lt;/p&gt;

&lt;h3&gt;
  
  
  Operations on the state
&lt;/h3&gt;

&lt;p&gt;Let us say that we have the state and several operations that we want to perform on the state like &lt;strong&gt;increment&lt;/strong&gt;, &lt;strong&gt;decrement&lt;/strong&gt;, &lt;strong&gt;reset&lt;/strong&gt; (to 0), and &lt;strong&gt;set&lt;/strong&gt; (to a custom value). &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In that case, the code could be designed in such a way that we take the state, perform an action on it: &lt;strong&gt;INCREMENT&lt;/strong&gt;, &lt;strong&gt;DECREMENT&lt;/strong&gt;, &lt;strong&gt;RESET&lt;/strong&gt; or &lt;strong&gt;SET&lt;/strong&gt; and the we get the new value. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But what we defined above is the textbook definition of a reducer function!&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YvnbYIMn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/azh377ulhyfz5mfo1d15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YvnbYIMn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/azh377ulhyfz5mfo1d15.png" alt="A reducer function" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And thus, our use case can be accomplished with the &lt;code&gt;useReducer&lt;/code&gt; hook because it allows us to create a &lt;em&gt;reducer&lt;/em&gt; inside of our React component. &lt;/p&gt;
&lt;h3&gt;
  
  
  Writing the reducer
&lt;/h3&gt;

&lt;p&gt;With that understanding, let us write our &lt;em&gt;reducer&lt;/em&gt; function. This is the function that React will call with the current state and the dispatched event type (whenever we dispatch one).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;reducerFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;INCREMENT&lt;/span&gt;&lt;span class="dl"&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;state&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DECREMENT&lt;/span&gt;&lt;span class="dl"&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;state&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;RESET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SET&lt;/span&gt;&lt;span class="dl"&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;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;val&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;And that's it. With just those lines of code, we've set up state management for our complex use case. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;☝🏾 Do not that the example of state to be a single number is just for the sake of explaining the concept and in react world, you would have complex objects as your core state and your would have to write logic inside your reducer to manage it correctly. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With that reducer, we can then initialise everything like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducerFunc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Count : &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
// rest of the code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, whenever we need to dispatch any changes to the state, we do something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;INCREMENT&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;increment&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And React will take care of the rest. &lt;/p&gt;

&lt;h3&gt;
  
  
  The reducer flow
&lt;/h3&gt;

&lt;p&gt;Basically, this is what happens when we call the &lt;code&gt;dispatch&lt;/code&gt; function provided to us by &lt;code&gt;useReducer&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React calls the function that you initially supplied to &lt;code&gt;useReducer&lt;/code&gt; and passes to it the arguments we supplied to &lt;code&gt;dispatch&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;The reducer function then makes some calculations based on some business logic. &lt;/li&gt;
&lt;li&gt;The value that gets returned by the reducer function becomes the new &lt;strong&gt;state&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This graphic sums it up well:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PZIY1sb8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bl7n2m9skof16x1ohan6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PZIY1sb8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bl7n2m9skof16x1ohan6.png" alt="reducer flow" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So basically, it is like having entire redux inside the scope of your React component. &lt;/p&gt;

&lt;p&gt;Hope that clears a lot of confusion around the &lt;code&gt;useReducer&lt;/code&gt; hook and the basic concept of a &lt;strong&gt;reducer&lt;/strong&gt; function. &lt;/p&gt;

&lt;p&gt;Cheers! 🙌🏾&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Mastering React's Context: A Guide to Efficient State Propagation</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Sun, 09 Jul 2023 08:48:05 +0000</pubDate>
      <link>https://dev.to/kokaneka/mastering-reacts-context-a-guide-to-efficient-state-propagation-4804</link>
      <guid>https://dev.to/kokaneka/mastering-reacts-context-a-guide-to-efficient-state-propagation-4804</guid>
      <description>&lt;p&gt;Hey There,&lt;/p&gt;

&lt;p&gt;Welcome to the third post in this &lt;strong&gt;React Demystified&lt;/strong&gt; series.&lt;/p&gt;




&lt;p&gt;Last week, we looked into the &lt;code&gt;useEffect&lt;/code&gt; hook and tried to understand why it's called that. And also, some fundamental questions like - What exactly is an effect? &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="/kokaneka" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XERE2L0Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--itHkFn_r--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/185874/e587dd79-ed59-41d0-8fe8-50b345cb7c2b.jpeg" alt="kokaneka"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/kokaneka/things-that-no-one-ever-told-you-about-useeffect-in-react-5fij" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Things that no one ever told you about useEffect() in React&lt;/h2&gt;
      &lt;h3&gt;kapeel kokane ・ Jul 3&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;





&lt;p&gt;This week, we dig into the React's &lt;code&gt;Context&lt;/code&gt; and the &lt;code&gt;useContext&lt;/code&gt; hook. We will dig into the core of what we mean by &lt;strong&gt;Context&lt;/strong&gt; and what is the significance of managing it throughout your React app. Let's do this! 🙌🏾&lt;/p&gt;

&lt;h2&gt;
  
  
  Some context about &lt;code&gt;Context&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kH68pHtE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xjnpg24nnt55xoq46m2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kH68pHtE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xjnpg24nnt55xoq46m2.png" alt="Why do you need context?" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We looked at state in our first article in this series &amp;amp; found out that state is something that the UX was tightly coupled with. It was that data, which if changed, would required the UX displayed to the user change as well. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So what is &lt;code&gt;Context&lt;/code&gt;?&lt;/strong&gt;&lt;br&gt;
According to the &lt;a href="https://react.dev/learn/passing-data-deeply-with-context"&gt;official docs&lt;/a&gt;, &lt;code&gt;Context&lt;/code&gt; is primarily an alternative to passing props:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H23fpuQL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yh482lklsqdl8im85dc5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H23fpuQL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yh482lklsqdl8im85dc5.png" alt="What is context" width="800" height="98"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What does that mean?&lt;br&gt;
Well, I understand Context as this - It is that data which &lt;strong&gt;does not change frequently&lt;/strong&gt;, is relatively &lt;strong&gt;small in size&lt;/strong&gt; and can be &lt;strong&gt;consumed anywhere&lt;/strong&gt; in the entire application. &lt;/p&gt;
&lt;h2&gt;
  
  
  An example of Context
&lt;/h2&gt;

&lt;p&gt;Let us say that there is some data that does not change frequently - Like the &lt;code&gt;theme&lt;/code&gt; associated with a website. If we create the theme at the top, like the App component and then want to use it in a button which was several layers deep, we would have to pass it down all the way. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RhooFF7l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7bcobl818heb3qxiogop.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RhooFF7l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7bcobl818heb3qxiogop.png" alt="Prop drilling" width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is more commonly known as prop drilling. &lt;/p&gt;

&lt;p&gt;The use of &lt;code&gt;Context&lt;/code&gt; solves this problem. Because instead of passing the piece of data through all the components where it does not get used, we only need three touchpoints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;creation&lt;/strong&gt; - Where the &lt;code&gt;Context&lt;/code&gt; is created&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;updation&lt;/strong&gt; - Where the &lt;code&gt;Context&lt;/code&gt; value can be updated&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;consumption&lt;/strong&gt; - Where the &lt;code&gt;Context&lt;/code&gt; value can be read. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This sketchnote below summarizes it well:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--APRzaLgn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rfbgiwiw39vvgs6vptct.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--APRzaLgn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rfbgiwiw39vvgs6vptct.png" alt="3 touchpoints of context" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that is what makes &lt;code&gt;Context&lt;/code&gt; special. Because it provides us with an interface to tap into this &lt;code&gt;context&lt;/code&gt; that is somehow magically available to us throughout the app. &lt;/p&gt;
&lt;h2&gt;
  
  
  Coding it up
&lt;/h2&gt;

&lt;p&gt;With that theoretical understanding, let us now work with &lt;code&gt;Context&lt;/code&gt; with some code. We will look at it from the perspective of the 3 touchpoints discussed above.&lt;/p&gt;
&lt;h3&gt;
  
  
  Context creation
&lt;/h3&gt;

&lt;p&gt;For creating &lt;code&gt;Context&lt;/code&gt; we use the &lt;code&gt;createContext&lt;/code&gt; function provided to us by React.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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;createContext&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;themeContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how the created &lt;code&gt;Context&lt;/code&gt; is exported out from this component. That is because in order to consume the &lt;code&gt;Context&lt;/code&gt; in any child component, we would first have to import this exported variable (which we will see next). &lt;/p&gt;

&lt;h3&gt;
  
  
  Context consumption
&lt;/h3&gt;

&lt;p&gt;Now, in order to consume the context value created without passing it down as props, we will need to import the above context variable and call the &lt;code&gt;useContext&lt;/code&gt; hook that will return us the current value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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;useContext&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ThemeContext&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;./App.js&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="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&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;theme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ThemeContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code runs and, &lt;code&gt;theme&lt;/code&gt; gets the value of &lt;strong&gt;light&lt;/strong&gt;, which was the default value set on the context. &lt;/p&gt;

&lt;p&gt;But, you might wonder what was the need to do all this?&lt;/p&gt;

&lt;p&gt;We can get the same result by just creating a constant named theme and exporting it from the &lt;code&gt;App.js&lt;/code&gt; component. But that is where the next part comes into the picture. &lt;/p&gt;

&lt;h3&gt;
  
  
  Context modification with &lt;code&gt;Provider&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Anywhere down the component tree below the context creation, its value can be edited using the &lt;code&gt;Provider&lt;/code&gt; component. &lt;/p&gt;

&lt;p&gt;So, let us say we had a button to tweak the light and dark theme. If that button was tied to a state variable, the current value of the state variable that the button controls could be provided as the value for the provider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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;ThemeContext&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;./App.js&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="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;children&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;theme&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setTheme&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&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;toggleTheme&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="nx"&gt;setTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&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;dark&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;light&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;section&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;LevelContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;LevelContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt; // This button toggles theme
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;section&lt;/span&gt;&lt;span class="p"&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;Once we have this in place, if we try to read the &lt;code&gt;Context&lt;/code&gt; value anywhere using &lt;code&gt;useContext&lt;/code&gt; down the component tree inside of &lt;code&gt;children&lt;/code&gt;, we will get the value that is set by this provider. Which inturn is being set via the button. &lt;/p&gt;

&lt;p&gt;Hope that clears a lot of concepts related to &lt;code&gt;Context&lt;/code&gt; in React and the &lt;code&gt;useContext&lt;/code&gt; hook. &lt;/p&gt;

&lt;p&gt;See you in the next one!&lt;/p&gt;

&lt;p&gt;Cheers 🙌🏾&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Things that no one ever told you about useEffect() in React</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Mon, 03 Jul 2023 10:37:45 +0000</pubDate>
      <link>https://dev.to/kokaneka/things-that-no-one-ever-told-you-about-useeffect-in-react-5fij</link>
      <guid>https://dev.to/kokaneka/things-that-no-one-ever-told-you-about-useeffect-in-react-5fij</guid>
      <description>&lt;p&gt;Hello there!&lt;/p&gt;

&lt;p&gt;Welcome to another &lt;strong&gt;React demystified&lt;/strong&gt; post. &lt;/p&gt;




&lt;p&gt;Last week, we covered the &lt;code&gt;useState()&lt;/code&gt; hook. We took it to the fundamental level and asked ourselves the question - "&lt;strong&gt;What exactly is state?&lt;/strong&gt;" 🤔.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/kokaneka" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XERE2L0Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--itHkFn_r--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/185874/e587dd79-ed59-41d0-8fe8-50b345cb7c2b.jpeg" alt="kokaneka"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/kokaneka/demystifying-reacts-usestate-hook-understanding-the-concept-of-state-e2n" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Demystifying useState(): Understanding the concept of "state"&lt;/h2&gt;
      &lt;h3&gt;kapeel kokane ・ Jun 25&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;





&lt;p&gt;In this week's post, we will look at the &lt;code&gt;useEffect()&lt;/code&gt; hook. It is one of the complicated things that you need to deal with, while working on &lt;strong&gt;functional React&lt;/strong&gt; components. But once you get the hang of it, there's no looking back. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;useEffect()&lt;/code&gt; is an escape hatch
&lt;/h2&gt;

&lt;p&gt;Look at this seemingly harmless piece of code &amp;amp; tell me what you think the output is going to be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="nx"&gt;App&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;first&lt;/span&gt;&lt;span class="dl"&gt;'&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="o"&gt;=&amp;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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;second&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;third&lt;/span&gt;&lt;span class="dl"&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello World&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&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;At first glance, it looks as though the output will be &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;first&lt;/li&gt;
&lt;li&gt;second&lt;/li&gt;
&lt;li&gt;third&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But, but, but...&lt;/p&gt;

&lt;p&gt;The actual output is&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;first &lt;/li&gt;
&lt;li&gt;third &lt;/li&gt;
&lt;li&gt;second&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let us understand why that is the case. &lt;/p&gt;

&lt;p&gt;If you notice closely, &lt;code&gt;useEffect&lt;/code&gt; is a function, that takes in another function as its first argument. It then calls executes that function at a future point in time. Turns out, that it always calls the function after the React component is &lt;em&gt;rendered&lt;/em&gt; and the &lt;em&gt;DOM is updated&lt;/em&gt;. Even in case of the first render. If you are not clear about how a React component gets translated into something on the DOM, check out this video:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/mECV6nGOqNo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The explanation
&lt;/h2&gt;

&lt;p&gt;Now that we see &lt;code&gt;useEffect()&lt;/code&gt; as a kind of escape hatch than anything else, the above behaviour makes more sense. &lt;/p&gt;

&lt;p&gt;What happens is this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;console.log(first)&lt;/code&gt; is executed and we see &lt;strong&gt;first&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useEffect&lt;/code&gt; is executed and we supply a function to it&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;console.log(third)&lt;/code&gt; is executed and we see &lt;strong&gt;third&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;React component is rendered, DOM update happens&lt;/li&gt;
&lt;li&gt;useEffect executes the function we supplied &amp;amp; we see &lt;strong&gt;second&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;"So what is the point of the useEffect hook if it comes into the picture after the DOM is updated?", you might ask. &lt;/p&gt;

&lt;p&gt;Well, it is to trigger &lt;strong&gt;side-effects&lt;/strong&gt; (external). &lt;/p&gt;

&lt;p&gt;According to the &lt;a href="https://react.dev/reference/react/useEffect"&gt;new React docs&lt;/a&gt;, it is quite clear what useEffect is meant for:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C1m6TYPx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/irykc9oekc3zxj84wfgw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C1m6TYPx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/irykc9oekc3zxj84wfgw.png" alt="useEffect official" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what does this sentence - "synchronize with external system" actually mean?&lt;/p&gt;

&lt;p&gt;Well, simply put, it means all the things that are "outside" of the React component. That includes things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;API&lt;/strong&gt; calls&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DB&lt;/strong&gt; interactions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Subscribing&lt;/strong&gt; to external events&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;So whenever you see any &lt;code&gt;useEffect&lt;/code&gt;, now you know that it is an escape hatch to take you out of the &lt;em&gt;normal flow of code&lt;/em&gt; and do things that deal with external systems. Although the code is placed inside of the function component (to take advantage of the &lt;strong&gt;closure property&lt;/strong&gt; &amp;amp; &lt;strong&gt;access local variables&lt;/strong&gt;), do not think of it as something that executes in the same flow. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The usage
&lt;/h2&gt;

&lt;p&gt;With that understanding in place, let us look at a few use cases of &lt;code&gt;useEffect&lt;/code&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  Side-effect on every render
&lt;/h3&gt;

&lt;p&gt;This happens when we write code that looks something like the example above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&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="o"&gt;=&amp;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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;every render&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello World&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&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;This kind of defeats the purpose of &lt;code&gt;useEffect&lt;/code&gt; as it runs the side-effect &lt;strong&gt;every time&lt;/strong&gt; the component is rendered. &lt;/p&gt;

&lt;h3&gt;
  
  
  side-effect once
&lt;/h3&gt;

&lt;p&gt;If we pass an empty array as the second argument to useEffect, we are letting it know to run our function only once - &lt;strong&gt;right after the first render&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&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="o"&gt;=&amp;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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;after first render&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello World&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&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;h3&gt;
  
  
  side-effect on dependency change
&lt;/h3&gt;

&lt;p&gt;In this use-case, we are instructing &lt;code&gt;useEffect&lt;/code&gt; to run the function every time a &lt;strong&gt;dependency is changed&lt;/strong&gt; (by specifying the dependency in the array). This might be useful if the side-effect is dependent on the dependency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&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="o"&gt;=&amp;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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;count changed&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="nx"&gt;count&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello World&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&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;h3&gt;
  
  
  summary
&lt;/h3&gt;

&lt;p&gt;This sketchnote summarises it well:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C3IwDh26--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8v5e8jw2pkemz63n3f6y.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C3IwDh26--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8v5e8jw2pkemz63n3f6y.jpeg" alt="useEffect summary" width="800" height="572"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope that this article cleared up a lot of things like the need for something like &lt;code&gt;useEffect()&lt;/code&gt; in the React paradigm. Also, hope that the 3 use cases are clear and that you will feel more confident in your "effects" henceforth. &lt;/p&gt;

&lt;p&gt;Cheers! 🙌🏾&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Demystifying useState(): Understanding the concept of "state"</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Sun, 25 Jun 2023 12:57:26 +0000</pubDate>
      <link>https://dev.to/kokaneka/demystifying-reacts-usestate-hook-understanding-the-concept-of-state-e2n</link>
      <guid>https://dev.to/kokaneka/demystifying-reacts-usestate-hook-understanding-the-concept-of-state-e2n</guid>
      <description>&lt;p&gt;If you've clicked on this article link, I assume you have used &lt;a href="https://react.dev/learn"&gt;React&lt;/a&gt;. &lt;br&gt;
Also, if you've done any decent React development in the recent past (after the class components were retired), the first thing that you would've learned is the &lt;code&gt;useState&lt;/code&gt; &lt;a href="https://react.dev/reference/react/useState"&gt;hook&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;You understand how to use the hook but do you understand the rationale behind its existence in the first place?&lt;/p&gt;

&lt;p&gt;Let's try to understand just that. &lt;/p&gt;


&lt;h3&gt;
  
  
  The static site
&lt;/h3&gt;

&lt;p&gt;If the primary use case of React websites was to define static websites, the ones from the early days of the web, we would have had no need for &lt;code&gt;useState&lt;/code&gt;. We could just do something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="nx"&gt;StaticSite&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="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Some static header&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Some static content that will never change&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&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;But, the issue is that static sites were a thing of the 90s (or maybe even before that). Nowadays, we need to have all sorts of functionality like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Responding to user button clicks&lt;/li&gt;
&lt;li&gt;Responding to scroll events&lt;/li&gt;
&lt;li&gt;Changing content on route change (in case of SPA)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short, a UX library needs to be &lt;strong&gt;reactive&lt;/strong&gt;. (Is that why it's called React? 🤔)&lt;/p&gt;




&lt;h3&gt;
  
  
  Reactivity
&lt;/h3&gt;

&lt;p&gt;This is a common word that basically means - &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;How does the library ensure that the UX rendered on the browser accurately represent the underlying state of the application&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For instance, if you are implementing a counter web app and the user has clicked the &lt;strong&gt;increment&lt;/strong&gt; button, how does the library take care that the incremented value is displayed?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GUDPOWSz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/syf6frarg2zy6cjawwll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GUDPOWSz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/syf6frarg2zy6cjawwll.png" alt="Reactivity in React" width="800" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that is exactly where &lt;code&gt;useState&lt;/code&gt; comes into the picture. &lt;/p&gt;

&lt;p&gt;But, before getting into that, let's take a small detour and understand how React works in the first place.&lt;/p&gt;




&lt;h3&gt;
  
  
  A quick detour
&lt;/h3&gt;

&lt;p&gt;When we use React as a library to create web apps, this is how it works:&lt;/p&gt;

&lt;p&gt;We write some React code that faithfully represents a user interface to be shown on the browser. There are some &lt;em&gt;static&lt;/em&gt; parts to this and some &lt;em&gt;dynamic&lt;/em&gt; parts. In the context of a counter, this is what it would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="nx"&gt;App&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;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Counter app&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;increment&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&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;The JSX that is returned from inside of this function is what React uses to create React element. It then compares the generated tree with the version of &lt;strong&gt;React DOM&lt;/strong&gt; and then &lt;em&gt;renders&lt;/em&gt; the result if necessary. Watch this quick video if you need more clarity on this:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/AwW7olQ84Qs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Basically it's this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hUk2RdnG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3deion25qv4nwcuials.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hUk2RdnG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3deion25qv4nwcuials.png" alt="Rendering in React" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Why &lt;code&gt;useState&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;With that context set, let us now explore what would happen if there was no &lt;code&gt;useState&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This is what our code would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="nx"&gt;App&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;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Counter app&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&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;increment&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;/main&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="si"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this is perfectly legal code, you will see that upon clicking the button, nothing happens. &lt;br&gt;
And that is because, we are just changing a normal variable, and not a &lt;strong&gt;state&lt;/strong&gt; variable. &lt;/p&gt;

&lt;p&gt;And that is the core concept of this article. In React, the UI that is generated and shown to the user is a function of the state. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--omqV_ns0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqzzre35vt46i4uqc0c1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--omqV_ns0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqzzre35vt46i4uqc0c1.png" alt="UI as a function of state in React" width="800" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And since not all variables used in the component are state variables, the useState hook helps us define those few special variables that form the state. &lt;/p&gt;

&lt;p&gt;It tells React to recompute the state when any of those variables changes. And whenever the state variable changes, React knows what it's time for - A UI update (if required). &lt;/p&gt;

&lt;p&gt;Hope you learned something new today. 🙌🏾&lt;br&gt;
Cheers!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>react</category>
      <category>programming</category>
    </item>
    <item>
      <title>100+ JavaScript concepts, same app using 7 frameworks &amp; CSS flex explained the right way</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Sun, 27 Nov 2022 11:00:45 +0000</pubDate>
      <link>https://dev.to/kokaneka/100-javascript-concepts-same-app-using-7-frameworks-css-flex-explained-the-right-way-5cdf</link>
      <guid>https://dev.to/kokaneka/100-javascript-concepts-same-app-using-7-frameworks-css-flex-explained-the-right-way-5cdf</guid>
      <description>&lt;p&gt;Hey there, fellow visual learner! 🙌🏾&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is the post for the last week of November. Black friday is here and it’s a great time to buy some of those development courses that you have been eyeing for a long time. Some lifetime deals on creator tools at the end of this newsletter.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s get started ⏳&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F5yhowa9fm4dmycinzrnj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5yhowa9fm4dmycinzrnj.gif" alt="Let's get started" width="400" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;❶ &lt;strong&gt;100+ JS concepts&lt;/strong&gt; in less than 13 minutes&lt;/p&gt;

&lt;p&gt;The Fireship YouTube channel put out a fantastic &lt;a href="https://www.youtube.com/watch?v=lkIFF4maKMU" rel="noopener noreferrer"&gt;video&lt;/a&gt; explaining 100+ JavaScript concepts. How many of these concepts do you have a grip on?&lt;/p&gt;

&lt;p&gt;❷ Learn &lt;strong&gt;CSS Flex&lt;/strong&gt; interactively&lt;/p&gt;

&lt;p&gt;Josh Comeau released this excellent interactive CSS Flex tutorial on his &lt;a href="https://www.joshwcomeau.com/css/interactive-guide-to-flexbox" rel="noopener noreferrer"&gt;blog&lt;/a&gt;. You can actually play around with the controls to tweak the flex parameters. Have fun!&lt;/p&gt;

&lt;p&gt;❸ &lt;strong&gt;Compare 7 frameworks&lt;/strong&gt; by building the same app&lt;/p&gt;

&lt;p&gt;Builder.io published an &lt;a href="https://www.builder.io/blog/movies-app-in-7-frameworks-which-is-fastest-and-why" rel="noopener noreferrer"&gt;article&lt;/a&gt; (extending some original work by Dan Shappir) where they compared the performance of 7 frameworks by building the same app. They test out React, Vue, Angular, Preact, and Svelte and compare them with Qwik's performance.&lt;/p&gt;

&lt;p&gt;🐥 &lt;strong&gt;FREE web development&lt;/strong&gt; courses&lt;/p&gt;

&lt;p&gt;In this week’s Twitter thread, we have Madza sharing some courses you could take to level up your web development. Click on the tweet below to check out the full thread. 👇🏾&lt;/p&gt;

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

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



&lt;/p&gt;

&lt;p&gt;🎁 Extra:&lt;/p&gt;

&lt;p&gt;As this is the Black Friday/Cyber Monday weekend, here are some lifetime deals on creator tools that you might like:&lt;/p&gt;

&lt;p&gt;① An &lt;strong&gt;AI image&lt;/strong&gt; generator &lt;a href="https://appsumo.8odi.net/ZdOGa1" rel="noopener noreferrer"&gt;tool&lt;/a&gt; (similar to DALL-E).&lt;/p&gt;

&lt;p&gt;② A &lt;strong&gt;social media scheduler&lt;/strong&gt; &lt;a href="https://appsumo.8odi.net/0JW6qV" rel="noopener noreferrer"&gt;tool&lt;/a&gt; (similar to Buffer, Feedhive)&lt;/p&gt;

&lt;p&gt;③ An &lt;strong&gt;AI-based writer&lt;/strong&gt; &lt;a href="https://appsumo.8odi.net/WDne5M" rel="noopener noreferrer"&gt;tool&lt;/a&gt; for generating blog articles, product descriptions, and more.&lt;/p&gt;

&lt;p&gt;That's it for today's edition. See you in the next one.&lt;/p&gt;

&lt;p&gt;Cheers! 🙌🏾&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>discuss</category>
    </item>
    <item>
      <title>A free &amp; open source tool by Facebook to create your blog site</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Mon, 28 Mar 2022 18:03:00 +0000</pubDate>
      <link>https://dev.to/kokaneka/a-free-open-source-tool-by-facebook-to-create-your-blog-site-4p2</link>
      <guid>https://dev.to/kokaneka/a-free-open-source-tool-by-facebook-to-create-your-blog-site-4p2</guid>
      <description>&lt;p&gt;Hey There 👋🏾&lt;/p&gt;

&lt;p&gt;Are you looking to start a developer blog soon? &lt;/p&gt;

&lt;p&gt;Do you already have one but you are not happy with it and want to migrate it?&lt;/p&gt;

&lt;p&gt;I have news for you. Read along 👇🏾&lt;/p&gt;

&lt;h3&gt;
  
  
  Features
&lt;/h3&gt;

&lt;p&gt;Before jumping into why this tool is amazing, let us first set the definition for what makes a blogging tool great. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It let's you write in &lt;strong&gt;markdown&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;There definitely needs to be code &lt;strong&gt;syntax&lt;/strong&gt; highlighting&lt;/li&gt;
&lt;li&gt;markdown is not enough, there need to be &lt;strong&gt;custom elements&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;There should be a support to create custom &lt;strong&gt;non-markdown&lt;/strong&gt; pages&lt;/li&gt;
&lt;li&gt;And off-course, a &lt;strong&gt;dark mode&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;How about a &lt;strong&gt;site-wide search&lt;/strong&gt; as well?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What if I told you that there is a framework that supports all these features right out of the box and that it is freely available?&lt;/p&gt;

&lt;p&gt;Well, here it is: &lt;a href="https://docusaurus.io/"&gt;Docusaurus&lt;/a&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kfgavH8Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/adgocyjzapnasf4imwh9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kfgavH8Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/adgocyjzapnasf4imwh9.png" alt="docusaurus image" width="800" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is a documentation framework by Facebook which is used by some of the giants in the industry like: &lt;a href="https://ionicframework.com/docs"&gt;ionic&lt;/a&gt;, &lt;a href="https://react-redux.js.org/"&gt;redux&lt;/a&gt;, &lt;a href="https://reactnative.dev/"&gt;react native&lt;/a&gt; and hundreds more as mentioned on this &lt;a href="https://docusaurus.io/showcase"&gt;page&lt;/a&gt;. But do not assume it to be just a documentation tool. &lt;/p&gt;

&lt;p&gt;It is an all inclusive toolkit to build full-fledged website like this one: &lt;a href="https://www.techinterviewhandbook.org/"&gt;Technical Interview Handbook&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's the main page custom built with React:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JPLlY7jJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vdcb3zv3or8n1yojxsq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JPLlY7jJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vdcb3zv3or8n1yojxsq.png" alt="interview handbook main page" width="800" height="436"&gt;&lt;/a&gt;&lt;br&gt;
The brilliance of the website above is that they have even customized it to show &lt;strong&gt;Carbon Ads&lt;/strong&gt; in the sidebar. &lt;/p&gt;

&lt;p&gt;Here's how a sample page in the site looks like:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vlolfgjd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0ldloeqsa958f9i7y35.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vlolfgjd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0ldloeqsa958f9i7y35.png" alt="interview handbook sample article" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice the green visual element. It adds a nice touch to the UI. Good enough for a blog site, right?&lt;/p&gt;

&lt;p&gt;Interested? Want to know how to create your own?&lt;/p&gt;

&lt;p&gt;This video will guide you with just that:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/wDUSzD8VZtY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  In the video:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A walkthough of docusaurus &lt;strong&gt;features&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;How to create a &lt;strong&gt;home&lt;/strong&gt; page&lt;/li&gt;
&lt;li&gt;How to utilize the &lt;strong&gt;blog&lt;/strong&gt; feature&lt;/li&gt;
&lt;li&gt;How to utilize the &lt;strong&gt;tutorial&lt;/strong&gt; feature&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cheers! 🙌🏾&lt;/p&gt;

</description>
      <category>react</category>
      <category>markdown</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Five* JavaScript concepts for your next interview</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Fri, 04 Feb 2022 17:49:32 +0000</pubDate>
      <link>https://dev.to/kokaneka/five-javascript-concepts-for-your-next-interview-3fdd</link>
      <guid>https://dev.to/kokaneka/five-javascript-concepts-for-your-next-interview-3fdd</guid>
      <description>&lt;p&gt;Hey There! 👋🏾&lt;/p&gt;

&lt;p&gt;Hope you are doing well. &lt;/p&gt;

&lt;p&gt;Have you worked on several projects that use &lt;strong&gt;JavaScript&lt;/strong&gt;, &lt;strong&gt;Node.js&lt;/strong&gt; or &lt;strong&gt;React.js&lt;/strong&gt; before but never found the time to actually study the core concepts of the language?&lt;/p&gt;

&lt;p&gt;OR &lt;/p&gt;

&lt;p&gt;Do you have an interview coming up and need a quick revision?&lt;/p&gt;

&lt;p&gt;Do not worry. You are not alone! &lt;/p&gt;

&lt;p&gt;In today's article, we look into some super important concepts related to the language that make or break an interview. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--azsT5nqc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxqgpb3tznlokmldrese.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--azsT5nqc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxqgpb3tznlokmldrese.gif" alt="Image description" width="400" height="202"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Event propagation
&lt;/h3&gt;

&lt;p&gt;This is an interviewer's favourite and checks your concepts related to &lt;strong&gt;event handlers&lt;/strong&gt;, &lt;strong&gt;bubbling&lt;/strong&gt; and &lt;strong&gt;capturing&lt;/strong&gt; of events. Here is a quick summary:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/0cYZjrUkZ5o"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Scope
&lt;/h3&gt;

&lt;p&gt;Next up is the concept of scope in JavaScript. This is important too because it forms the basis for understanding other advanced concepts like closures. &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/FSAQxiwqeG0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Closures
&lt;/h3&gt;

&lt;p&gt;This is the all-time interviewer favourite and it is so for a reason. This concept checks several other underlying concepts and an in-depth understanding of the language. &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/e8_bZ3zhYPE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Prototypal inheritance
&lt;/h3&gt;

&lt;p&gt;The kind of inheritance in JavaScript is different from that in other languages like Java and c++ and that is what makes it all the way more important to understand how that works.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/e8_bZ3zhYPE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Strict mode
&lt;/h3&gt;

&lt;p&gt;Did you know there is a strict mode in JavaScript? Although rare, this question still comes up sometimes in an interview and it is a good idea to have some clue regarding what it is all about. &lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/H5VV5Ebd8Yg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Bonus: !! Operator
&lt;/h3&gt;

&lt;p&gt;This is a bonus concept and maybe it would never get asked in any interview but is still an interesting concept to know about the language!&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/hjG-o-sWHq0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Hope you found all those helpful. 🙌🏾&lt;/p&gt;

&lt;p&gt;Go rock your next &lt;strong&gt;JavaScript&lt;/strong&gt; interview!&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Mint an NFT for FREE and sell it on Opensea [Complete guide]</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Sat, 04 Dec 2021 12:00:46 +0000</pubDate>
      <link>https://dev.to/kokaneka/mint-an-nft-for-free-and-sell-it-on-opensea-complete-guide-3eb6</link>
      <guid>https://dev.to/kokaneka/mint-an-nft-for-free-and-sell-it-on-opensea-complete-guide-3eb6</guid>
      <description>&lt;p&gt;For the past few months, we have been hearing a lot about the word &lt;strong&gt;web3&lt;/strong&gt;. Experts are hinting that this is the beginning of a new era wherein &lt;strong&gt;decentralisation&lt;/strong&gt; and &lt;strong&gt;transparency&lt;/strong&gt; will the the key factors powered by &lt;strong&gt;Blockchain technology&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;One of the amazing products that this technology brings to us is NFTs a.k.a (Non-fungible tokens). I'll not spend time explaining what they are and how they work. You can read this amazing &lt;a href="https://feedhive.io/blog/nfts-for-creators-is-it-time-to-get-onboard" rel="noopener noreferrer"&gt;article&lt;/a&gt;. &lt;/p&gt;




&lt;p&gt;Earlier this week, I minted my own NFT for free and in this article, I share the steps I followed so that you can get one for yourself too! 👇🏾&lt;/p&gt;

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

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



&lt;/p&gt;

&lt;p&gt;Let's begin 🙌🏾&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Create a Metamask account
&lt;/h3&gt;

&lt;p&gt;In order to login into &lt;a href="https://opensea.io/" rel="noopener noreferrer"&gt;Opensea&lt;/a&gt;, you do not need a username/password combo or an email. You need to login by linking the account with a crypto wallet. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ml6osmy4jvfj8uejigm.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%2F7ml6osmy4jvfj8uejigm.png" alt="metamask wallet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://metamask.io/" rel="noopener noreferrer"&gt;MetaMask&lt;/a&gt; is one such wallet which you can create for free. If you do not want to download or install anything, just add this &lt;a href="https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en" rel="noopener noreferrer"&gt;extension&lt;/a&gt; to your Chrome browser and get started. After adding the extension, follow the steps to get your MetaMask account by generating your passphrase and noting it down in a secure location. &lt;/p&gt;

&lt;h3&gt;
  
  
  2. Switch to Polygon network
&lt;/h3&gt;

&lt;p&gt;Most of the people are not aware that the MetaMask wallet allows users to hold tokens on several networks apart from the main etherium network (Etherium mainnet). As the cost of Etherium is very high and we do not want to spend a huge amount of gas fee (the cost of minting) while creating our NFT, we will switch to the Polygon network (Matic mainnet). Here's how to do that:&lt;/p&gt;

&lt;p&gt;Click on the dropdown that says &lt;strong&gt;Etherium Mainnet&lt;/strong&gt; and click on &lt;strong&gt;Add Network&lt;/strong&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft3tysbjwitgmmio8np97.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%2Ft3tysbjwitgmmio8np97.png" alt="Add matic wallet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the page that comes up, fill in the following details:&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Network Name&lt;/strong&gt;&lt;br&gt;
Matic Mainnet&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;New RPC URL&lt;/strong&gt; &lt;br&gt;
&lt;a href="https://rpc-mainnet.maticvigil.com/" rel="noopener noreferrer"&gt;https://rpc-mainnet.maticvigil.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chain ID&lt;/strong&gt; &lt;br&gt;
137&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Currency Symbol&lt;/strong&gt; &lt;br&gt;
MATIC&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Block Explorer URL&lt;/strong&gt; &lt;br&gt;
&lt;a href="https://explorer.matic.network/" rel="noopener noreferrer"&gt;https://explorer.matic.network/&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Click &lt;strong&gt;save&lt;/strong&gt;, and then select the newly added network from the dropdown which earlier showed &lt;strong&gt;Etherium Mainnet&lt;/strong&gt;, which should now show &lt;strong&gt;Matic Mainnet&lt;/strong&gt;.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn5xwr64fefxfykwifm9m.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%2Fn5xwr64fefxfykwifm9m.png" alt="change wallet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Get some MATIC flowing
&lt;/h3&gt;

&lt;p&gt;Once we switch the network to the Matic mainnet, we can also add some token into it by using some faucets. Faucets are free sites that provide a very small amount of tokens to you for free so that you can get started. Here are the links to two faucets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://matic.supply/" rel="noopener noreferrer"&gt;Matic.supply&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://macncheese.finance/matic-polygon-mainnet-faucet.php" rel="noopener noreferrer"&gt;Macncheese.finance&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Visit these links and follow the steps mentioned there which usually includes supplying your MetaMask ID and you will see the MATIC tokens in your wallet within a few minutes. &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%2Fa86exrm1tj33gnjt52x2.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%2Fa86exrm1tj33gnjt52x2.png" alt="matics in wallet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Create an OpenSea account
&lt;/h3&gt;

&lt;p&gt;Now that we have the MetaMask wallet set up, and some MATICs flowing in, let us link it to our Opensea account. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq289qmnsm6wd2hayf5r8.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%2Fq289qmnsm6wd2hayf5r8.png" alt="matics in wallet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visit this &lt;a href="https://opensea.io/login" rel="noopener noreferrer"&gt;link&lt;/a&gt; and click on MetaMask:&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%2F4wr07oh0j7v9uv9m9fak.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%2F4wr07oh0j7v9uv9m9fak.png" alt="connect metamask"&gt;&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Select the MetaMask wallet that we created just now and provide the required details to create the Opensea account. At the end of this step, your Opensea account would be ready.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0c6bp0g2u5pdrihab9t6.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%2F0c6bp0g2u5pdrihab9t6.png" alt="opensea account"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Mint an NFT
&lt;/h3&gt;

&lt;p&gt;Now to the juicy part: Actually minting the NFT. The tough part is already over and this is quite straight forward. &lt;/p&gt;

&lt;p&gt;Click on the &lt;strong&gt;Create&lt;/strong&gt; button near the top right corner which takes you to this interface. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0qo2rz4u7n3rzb6opgld.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%2F0qo2rz4u7n3rzb6opgld.png" alt="create NFT"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On this form, first upload the piece of media that you want to convert into an NFT. It could be an &lt;strong&gt;image&lt;/strong&gt;, a &lt;strong&gt;gif&lt;/strong&gt; or even a piece of &lt;strong&gt;music&lt;/strong&gt;. I chose an infographic which I created in order to explain the concept of &lt;strong&gt;Habit Loop&lt;/strong&gt; from the book &lt;strong&gt;Atomic Habits&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Next, provide all the mandatory information. &lt;/p&gt;

&lt;p&gt;It is important to switch the network to Polygon from the dropdown near the bottom so that you can avoid huge gas fees.&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%2F28k109qa4t6wp3cou6u0.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%2F28k109qa4t6wp3cou6u0.png" alt="switch network"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Create&lt;/strong&gt; and watch as your NFT is minted on the Polygon network in the next couple of minutes. &lt;/p&gt;

&lt;p&gt;Once done, you can view the NFT product page which would look something similar to &lt;a href="https://opensea.io/assets/matic/0x2953399124f0cbb46d2cbacd8a89cf0599974963/84793650486123568271099888450556127339575830697505335110669996533285614780417" rel="noopener noreferrer"&gt;mine&lt;/a&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faj1zv95hqqbtrl8u078l.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%2Faj1zv95hqqbtrl8u078l.png" alt="NFT product page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that's it! Congratulations! 🙌🏾&lt;/p&gt;

&lt;p&gt;You've successfully minted your first ever NFT.&lt;/p&gt;

&lt;p&gt;If you wish to sell this NFT, then click on the &lt;strong&gt;Sell&lt;/strong&gt; button near the top right and follow the steps. &lt;/p&gt;

&lt;p&gt;Do share your creations in the comments below so that I can check them out. See you in the next one.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>tutorial</category>
      <category>showdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>5 reasons why you need to create technical content consistently</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Sat, 27 Nov 2021 07:11:05 +0000</pubDate>
      <link>https://dev.to/kokaneka/5-reasons-why-you-need-to-create-technical-content-consistently-3dgo</link>
      <guid>https://dev.to/kokaneka/5-reasons-why-you-need-to-create-technical-content-consistently-3dgo</guid>
      <description>&lt;p&gt;Hi There 👋🏾&lt;/p&gt;

&lt;p&gt;Today, we will discuss a few factors related to content creation and why doing it everyday is what will differentiate you in the long run from others. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Although this applies to any kind of content, I will focus on &lt;strong&gt;JavaScript&lt;/strong&gt; and &lt;strong&gt;Webdev&lt;/strong&gt; related content in this post as that is my niche. You can extent the same principles to any other niche.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Another disclaimer: Although I am aware that creating content consistently has its own benefits, I am myself a culprit of not being able to follow it sometimes. Working on it and hoping to get better :)&lt;/p&gt;

&lt;p&gt;Back to the article. Here goes 👇🏾&lt;/p&gt;

&lt;h3&gt;
  
  
  Consistency brings discipline
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ipz19qCd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/XzQl9RV33mYAAAAC/you-need-to-be-consistent-get-it-together.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ipz19qCd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/XzQl9RV33mYAAAAC/you-need-to-be-consistent-get-it-together.gif" alt="descipline gif" width="498" height="278"&gt;&lt;/a&gt;&lt;br&gt;
The first benefit is a subtle one. By creating content daily, making a routine out of it, you are &lt;strong&gt;programming your brain&lt;/strong&gt; to do more and more of it. In other words, you are telling your &lt;strong&gt;sub-conscious mind&lt;/strong&gt; that this is something dear to you and you care about it. This in turn will make you come back to doing it again and again on a daily basis. &lt;/p&gt;
&lt;h3&gt;
  
  
  Improve your technical skills
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PSoatOZ4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/eaE2Dzi47H4AAAAC/ninja-ninjitsu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PSoatOZ4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/eaE2Dzi47H4AAAAC/ninja-ninjitsu.gif" alt="skills gif" width="458" height="200"&gt;&lt;/a&gt;&lt;br&gt;
One of the benefits of creating technical content is that you cannot do so without a firm grasp of the topic yourself. And in order to build that understanding, you need to &lt;strong&gt;do your research&lt;/strong&gt;. Which means, while creating the content and building your audience, you are also building the scope of your technical knowledge, which is the cherry on top!&lt;/p&gt;
&lt;h3&gt;
  
  
  Builds a positive keystone Habit
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5Dj-6GuE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/9qChZ6Y7i-gAAAAC/jamie-lee-curtis-behave.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5Dj-6GuE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/9qChZ6Y7i-gAAAAC/jamie-lee-curtis-behave.gif" alt="habits gif" width="498" height="266"&gt;&lt;/a&gt;&lt;br&gt;
One of the concepts explained by James Clear is &lt;a href="https://jamesclear.com/keystone-habits"&gt;keystone habits&lt;/a&gt;. It explains how one good habit has a &lt;strong&gt;butterfly effect&lt;/strong&gt; on all the other things that you do. For instance, in order to create content regularly, you might subscribe to some technical news feeds and start spending more time researching other blogs instead of mindless Instagram scrolling! &lt;/p&gt;
&lt;h3&gt;
  
  
  Build more connections
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EyrAUk9V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/4LvAD8hD5tcAAAAM/charlie-day.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EyrAUk9V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/4LvAD8hD5tcAAAAM/charlie-day.gif" alt="connections gif" width="220" height="140"&gt;&lt;/a&gt;&lt;br&gt;
This is a side effect of creating content. When you share your stuff and interact with others who are doing the same, you develop &lt;strong&gt;connections for a lifetime&lt;/strong&gt;. You get to interact with thought leaders in your niche and get their feedback on your work. Isn't that just amazing?&lt;/p&gt;
&lt;h3&gt;
  
  
  The Algorithm favours you
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u7E2zTnw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/WYEAk2FOwIUAAAAd/algorithm.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u7E2zTnw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://c.tenor.com/WYEAk2FOwIUAAAAd/algorithm.gif" alt="algorithm gif" width="640" height="544"&gt;&lt;/a&gt;&lt;br&gt;
This is the second cherry on top of the regular cherry that is on top of your content creation cake. As you might already be knowing, platforms like &lt;strong&gt;Linkedin&lt;/strong&gt;, &lt;strong&gt;Twitter&lt;/strong&gt;, &lt;strong&gt;YouTube&lt;/strong&gt; favour the ones who post regularly. There are examples of several folks who have grown to &lt;strong&gt;thousands of followers&lt;/strong&gt; in a span of less than a year who swear by creating content regularly. Here are a few of them:&lt;/p&gt;

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

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



&lt;/p&gt;

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

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



&lt;/p&gt;

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

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



&lt;/p&gt;

&lt;p&gt;With those points in mind, go ahead, start your journey to grow, learn and share with your fellow developers. All the very best. &lt;/p&gt;

&lt;p&gt;Cheeers!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;PS:&lt;/strong&gt; If you find yourself with many great ideas but you cannot seem to be regular, there are automation tools that can help you &lt;strong&gt;create once&lt;/strong&gt; and &lt;strong&gt;publish regularly&lt;/strong&gt;. One such tool is &lt;a href="https://appsumo.8odi.net/JrR45N"&gt;Feedive&lt;/a&gt;, created by the amazing &lt;a href="https://twitter.com/SimonHoiberg"&gt;Simon Hoiberg&lt;/a&gt; which lets you schedule content on all Social platforms from single place, provide analytics etc. Also, it lets you use in-house AI based tools that help you create more!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DYKQk1Et--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ocr58d8d3godcgczh5ae.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DYKQk1Et--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ocr58d8d3godcgczh5ae.png" alt="Feedhive banner" width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The usual payment more is 💰subscription💰 which is quite costly if you are a beginner. &lt;/p&gt;

&lt;p&gt;But, as a part of 🎊Black Friday🎊 promotions, Feedhive is available for $59. All yours, no questions asked! 🙌🏾 &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SRHiF-Qt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fmfp5e4bzn5ruxqk3bey.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRHiF-Qt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fmfp5e4bzn5ruxqk3bey.png" alt="Appsumo offer banner" width="800" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do check it out if you think that is something which might help you stay regular on your content creation journey!&lt;/p&gt;

&lt;p&gt;All the best :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>3 tips from "Atomic habits" that helped me on my journey to becoming a full-stack dev at Microsoft</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Wed, 06 Oct 2021 18:09:22 +0000</pubDate>
      <link>https://dev.to/kokaneka/3-tips-from-atomic-habits-that-helped-me-get-a-job-at-microsoft-56ih</link>
      <guid>https://dev.to/kokaneka/3-tips-from-atomic-habits-that-helped-me-get-a-job-at-microsoft-56ih</guid>
      <description>&lt;p&gt;Hey There 👋🏾&lt;/p&gt;

&lt;p&gt;Hope you are doing well. 🙌🏾&lt;/p&gt;

&lt;p&gt;I joined &lt;strong&gt;Microsoft&lt;/strong&gt; as a full-stack developer last month and the announcement tweet went viral on Twitter.&lt;/p&gt;

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

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



&lt;/p&gt;

&lt;p&gt;Many of the fellow devs asked me for my journey and what helped me reach there. So I thought of putting this article together by listing out a few small habits that added up over time which helped me get the desired result. Many of the things that I talk about are mentioned in the amazing book &lt;strong&gt;Atomic habits&lt;/strong&gt; by James Clear which I think, every human being must read at least once!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;disclaimer&lt;/strong&gt;: This article is not a place for &lt;strong&gt;tips and tricks&lt;/strong&gt; or a list of &lt;strong&gt;important questions&lt;/strong&gt; to crack any particular interview. It was a long &amp;amp; gradual process for me and I'm just listing down what worked for me. You can try it out and see if it works for you.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1️⃣ Design your environment
&lt;/h3&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%2Fc.tenor.com%2F_Ss12EWsZHEAAAAd%2Fplan-yoda-plan.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%2Fc.tenor.com%2F_Ss12EWsZHEAAAAd%2Fplan-yoda-plan.gif" alt="yoda plan"&gt;&lt;/a&gt;&lt;br&gt;
James talks about the power of &lt;a href="https://jamesclear.com/power-of-environment" rel="noopener noreferrer"&gt;environment design&lt;/a&gt; over motivation and here's how we can apply that. &lt;/p&gt;

&lt;h4&gt;
  
  
  Phone
&lt;/h4&gt;

&lt;p&gt;People say phones are distracting and toxic. I say people do not know how to use phones. If used properly, it can act as a prime weapon in your arsenal. &lt;br&gt;
Structure your home screen so that instead of Facebook, Instagram, you see &lt;a href="https://dev.to/"&gt;dev.to&lt;/a&gt;, &lt;a href="https://hashnode.com/" rel="noopener noreferrer"&gt;hashnode&lt;/a&gt;, &lt;a href="https://daily.dev/" rel="noopener noreferrer"&gt;daily.dev&lt;/a&gt; so that when you open your phone, the decision is easy for you to scroll some technical content instead of mindless binge-scrolling!&lt;/p&gt;

&lt;h4&gt;
  
  
  YouTube
&lt;/h4&gt;

&lt;p&gt;Most people under-estimate YouTube's capabilities when it comes to learning. You can create a separate Google account and only subscribe learning channels through it. That way, when you switch accounts from the menu bar, you get a nicely curated feed of tutorials and tech updates that you might be interested in. Here are a few awesome channels:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/c/TraversyMedia" rel="noopener noreferrer"&gt;Traversy media&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/c/Freecodecamp" rel="noopener noreferrer"&gt;Freecodecamp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/c/Academind" rel="noopener noreferrer"&gt;Academind&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Twitter
&lt;/h4&gt;

&lt;p&gt;Twitter is also an amazing place to learn and connect with industry experts. If you do not have a Twitter account, create one today and &lt;strong&gt;ONLY&lt;/strong&gt; follow the accounts that are creating content around the tech that you are interested in. That way, even if you wanted to binge-scroll, it will be curated. You can also follow accounts specific to a particular language like &lt;a href="https://twitter.com/JavaScript" rel="noopener noreferrer"&gt;Javascript&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2️⃣ Create systems
&lt;/h3&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%2Fc.tenor.com%2F2AQR9FgLS4UAAAAC%2Fdo-it-shia-la-beouf.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%2Fc.tenor.com%2F2AQR9FgLS4UAAAAC%2Fdo-it-shia-la-beouf.gif" alt="just do it"&gt;&lt;/a&gt;&lt;br&gt;
James also talks about the importance of &lt;a href="https://jamesclear.com/goals-systems" rel="noopener noreferrer"&gt;creating systems&lt;/a&gt; rather that setting goals to be successful in the long run. &lt;br&gt;
Hence, instead of trying to rely on motivation which comes and goes, try to set up systems. Those systems can be something like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set 7pm to 8pm as &lt;strong&gt;learning time&lt;/strong&gt; (can be any time slot)&lt;/li&gt;
&lt;li&gt;Listen to &lt;strong&gt;audio books&lt;/strong&gt; while taking a walk&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never&lt;/strong&gt; watch television alone&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These systems, once established in your mind would make it highly improbable for you not to do the right thing. And they also take out decision fatigue. For instance, if its 7:15pm, you definitely know that you must be learning stuff right now and hence you do that, without thinking much. &lt;/p&gt;

&lt;h3&gt;
  
  
  3️⃣ Identity based habits
&lt;/h3&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%2Fj8gaeekfy4dsa63ugw5r.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%2Fj8gaeekfy4dsa63ugw5r.png" alt="layers of identity"&gt;&lt;/a&gt;&lt;br&gt;
The third thing that can help you on your journey is this concept of &lt;a href="https://jamesclear.com/identity-based-habits" rel="noopener noreferrer"&gt;identity based habits&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;How this can help you on your tech journey is, instead of &lt;strong&gt;trying to build&lt;/strong&gt; stuff using a new tech stack, you can think of &lt;strong&gt;becoming&lt;/strong&gt; a curious developer. &lt;/p&gt;

&lt;p&gt;Instead of studying about algorithms and data structure, you can become the sort of person who &lt;strong&gt;wonders&lt;/strong&gt; about how stuff works. &lt;/p&gt;

&lt;p&gt;If you are also on the path of content creation, then don't try to create content. Become a person who &lt;strong&gt;shares knowledge&lt;/strong&gt; consistently. &lt;/p&gt;

&lt;p&gt;Maybe the examples that I provided are not perfect. Go through the article link that I provided and try to come up with your own identity that would help you stick to your habit.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Doing these things would push you in the direction wherein over a long term, you will see yourself grow as a developer. I did. For me, cracking the interviews was not just a process for those 3 or 4 months. It was an amalgamation of the things that I did over the last 5 years. If you are in it for the long run, you will definitely succeed. And even it you don't. there is nothing to loose here! 🙌🏾&lt;/p&gt;

&lt;p&gt;If you liked that, then consider following me on &lt;a href="https://twitter.com/Kokaneka" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; where I post content🎁 more frequently. &lt;/p&gt;

&lt;p&gt;Cheers ✌🏽&lt;/p&gt;

</description>
      <category>career</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>LRU cache Illustrated - For the visual learner</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Wed, 25 Aug 2021 18:22:41 +0000</pubDate>
      <link>https://dev.to/kokaneka/lru-cache-illustrated-for-the-visual-learner-242c</link>
      <guid>https://dev.to/kokaneka/lru-cache-illustrated-for-the-visual-learner-242c</guid>
      <description>&lt;p&gt;Hey There 👋🏾&lt;/p&gt;

&lt;p&gt;Today's topic of discussion is the &lt;strong&gt;LRU cache&lt;/strong&gt;. A few days back, I created a twitter thread giving an introduction about the same. Here's the thread if you want to take a look. 👇🏾&lt;/p&gt;

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

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



&lt;/p&gt;




&lt;p&gt;💁🏻‍♂️ In today's post, we will be digging in a little deeper and also look at how one can implement an LRU cache in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why cache anything? 🤔
&lt;/h2&gt;

&lt;p&gt;The first question that we will tackle is&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;why do we need to cache anything in the first place?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Well, the way software gets used by consumers follows a specific pattern. Somewhat similar to the &lt;a href="https://en.wikipedia.org/wiki/Pareto_principle" rel="noopener noreferrer"&gt;80-20 rule&lt;/a&gt;. It basically means that the data that gets queried once, is more likely to get queried on the same device again.&lt;/p&gt;

&lt;p&gt;And that even makes sense. Whenever I open twitter, as I'm definitely sure that my user information needs to be fetched every time, it's &lt;em&gt;an efficient choice&lt;/em&gt; to cache that information on my browser so that the next time it is required, there is a &lt;strong&gt;faster&lt;/strong&gt; way to fetch it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not cache everything? 🤨
&lt;/h2&gt;

&lt;p&gt;The next logical question would then be&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If caching is actually that good and solves all our problems, why don't we cache everything?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Well, there is the issue of &lt;strong&gt;space constraint&lt;/strong&gt;. In the previous example, if the browser starts caching all the user's info that I visit, sooner or later, the browser is going to &lt;em&gt;run out of memory&lt;/em&gt;. And hence, there needs to be a conscious thought about what to cache and for how long.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cache replacement!
&lt;/h2&gt;

&lt;p&gt;With that in mind, we now need to think about a scenario&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What if the cache is at full capacity right now and we need to add another element to it?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is where the &lt;strong&gt;LRU&lt;/strong&gt; part comes into the picture. Which expands to &lt;strong&gt;Least recently used&lt;/strong&gt;. The logic being that something which was used(stored/accessed) a long long time back, would most probably not be used again. There are other strategies of cache eviction (deletion) apart from the LRU one. They are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;First in first out:&lt;/strong&gt;
The one that was added first, gets deleted first, irrespective of when it got accessed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Last in first out:&lt;/strong&gt;
The one that was added last, gets deleted first, irrespective of when it got accessed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Least frequently used:&lt;/strong&gt;
The one that was accessed the fewest number of times, gets deleted first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Random replacement:&lt;/strong&gt;
Any one of the cache items is randomly chosen and deleted.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are several other strategies in addition to these. Also, there is no one-size-fits-all strategy and each of these mentioned above are suited for different use cases. But in today's article, we will be looking specifically into the LRU cache.&lt;/p&gt;

&lt;h2&gt;
  
  
  LRU illustrated
&lt;/h2&gt;

&lt;p&gt;Let us assume that we have an LRU cache that can only hold &lt;strong&gt;3 user details&lt;/strong&gt; at a time and visualise how that would look like. using the &lt;code&gt;put()&lt;/code&gt; method to add user to the cache and the &lt;code&gt;get()&lt;/code&gt; method to fetch the user info from the cache. Before adding anything, this is what the cache looks like:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo1cpxdan30ucggqnjf7e.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%2Fo1cpxdan30ucggqnjf7e.png" alt="empty cache"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's add the 3 users. Using string value for example, can be assumed to be an object with different key/value data about the user.&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="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;amy&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;amy's details&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bob&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;bob's details&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;clint&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;clint's details&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cache is now at full capacity and looks like this:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgaxslzkoyy8mlyvocuuw.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%2Fgaxslzkoyy8mlyvocuuw.png" alt="cache after 3 puts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, If we want to add a fourth user: dylan to the cache, one of the previous users needs to be deleted. And that would be amy according to the &lt;strong&gt;least recently used&lt;/strong&gt; principle.&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="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dylan&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;dylan's details&lt;/span&gt;&lt;span class="dl"&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;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%2Fh5qp6dmoadywg3ybln2e.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%2Fh5qp6dmoadywg3ybln2e.png" alt="dylan added to cache"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But, let's say if before adding dylan to the cache, if we had accessed amy's user object, it would &lt;strong&gt;NOT&lt;/strong&gt; be the least recently used item in the cache and due to that, bob would have got chucked out instead.&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="nx"&gt;cache&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="s1"&gt;amy&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dylan&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;dylan's details&lt;/span&gt;&lt;span class="dl"&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;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%2Fjgpdk177uqx7k0vf7mu8.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%2Fjgpdk177uqx7k0vf7mu8.png" alt="dylan added after amy accessed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope that provides you the gist of how this is working. Let's dive into the code!&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's code
&lt;/h2&gt;

&lt;p&gt;We will code this up as a JavaScript class with the &lt;code&gt;get&lt;/code&gt; and &lt;code&gt;put&lt;/code&gt; methods in it. &lt;/p&gt;

&lt;p&gt;Here's what the class looks like with it's constructor&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;class&lt;/span&gt; &lt;span class="nc"&gt;LRUCache&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&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;Map&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;capacity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;capacity&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;Here's the &lt;code&gt;get()&lt;/code&gt; method&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="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&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;-&lt;/span&gt;&lt;span class="mi"&gt;1&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;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&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="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&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="nx"&gt;key&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;The first line just checks whether the item is present in the cache and returns a -1 in case it is not. &lt;/p&gt;

&lt;p&gt;But do you notice the part wherein the object &lt;strong&gt;is present&lt;/strong&gt;? &lt;/p&gt;

&lt;p&gt;We access the value, delete it from the cache and then add it again before returning its value. Well that is a trick which you'll soon understand.&lt;/p&gt;

&lt;p&gt;Let's look at the &lt;code&gt;put()&lt;/code&gt; method before that:&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="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;capacity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;next&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="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;In the first part here, if the cache already has the key that we are trying to add, we delete it first and then add it again. This is confusing too, right?&lt;/p&gt;

&lt;p&gt;The next part will make it clear. &lt;/p&gt;

&lt;p&gt;Notice what we are doing in case the cache has exceeded capacity? we are doing &lt;code&gt;this.cache.keys().next().value&lt;/code&gt;. Well, this is a special trick using which we are fetching the value that was written &lt;strong&gt;first&lt;/strong&gt; out of all the values written to the Map. &lt;/p&gt;

&lt;p&gt;You see, in the &lt;code&gt;get()&lt;/code&gt; method, we deleted the key and set it again so that it ends up being the &lt;strong&gt;most recently added value&lt;/strong&gt; and does not show up when we fetch &lt;code&gt;this.cache.keys().next().value&lt;/code&gt; value as it got recently accessed.&lt;/p&gt;

&lt;p&gt;The deletion and adding inside the &lt;code&gt;put()&lt;/code&gt; function is serving a similar function. Basically, we are refreshing that particular value in the cache!&lt;/p&gt;

&lt;p&gt;And that's the magic. And we have this fully functional cache written in JavaScript which we can play around with!&lt;/p&gt;

&lt;p&gt;Hope you liked that. &lt;br&gt;
Cheers! 🙌🏾&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Facing writer's block? This FREE tool might help 🙌🏾</title>
      <dc:creator>kapeel kokane</dc:creator>
      <pubDate>Fri, 20 Aug 2021 14:16:23 +0000</pubDate>
      <link>https://dev.to/kokaneka/facing-writer-s-block-this-free-tool-might-help-a11</link>
      <guid>https://dev.to/kokaneka/facing-writer-s-block-this-free-tool-might-help-a11</guid>
      <description>&lt;p&gt;Hey There 👋🏾&lt;/p&gt;

&lt;p&gt;Hope you are doing great 🙌🏾&lt;/p&gt;

&lt;p&gt;In today's article, we do something different. I wanted to talk about a problem that I was recently facing and how I (almost) solved it. 🤞🏾&lt;/p&gt;




&lt;h2&gt;
  
  
  The pain is real
&lt;/h2&gt;

&lt;p&gt;Here's the thing. I have been wanting to be a good content creator for a long time now. Notice that I say a &lt;em&gt;good&lt;/em&gt; content creator. That's hard. &lt;/p&gt;

&lt;p&gt;The more and more I dug into &lt;strong&gt;hacks&lt;/strong&gt;, or &lt;strong&gt;shortcuts&lt;/strong&gt; to become a great content creator and grow a following, the more it became clear that there is actually no &lt;em&gt;secret&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;The only secret is that one keeps creating content consistently, regularly and becomes great over the time. That's it. &lt;/p&gt;

&lt;h2&gt;
  
  
  Walking the talk
&lt;/h2&gt;

&lt;p&gt;It's easy, then, right? Just keep writing an article a day and in the long run, you become great. Well, so I thought. 👀&lt;/p&gt;

&lt;p&gt;But it's easier said than done. Once you start walking on that path, many demons raise their head. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lack of time ⏰&lt;/li&gt;
&lt;li&gt;Lack of motivation 😪&lt;/li&gt;
&lt;li&gt;Lack of topics to write about ✍🏼&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Solving the problems
&lt;/h2&gt;

&lt;p&gt;The first 2 problems are mainly behavioural in nature. In order to solve them, I suggest you get certain very strong &lt;strong&gt;whys&lt;/strong&gt;. I'll explain. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;whys&lt;/strong&gt; are the reasons for which we do something. And the stronger the &lt;em&gt;why&lt;/em&gt; is, the stronger its emotional connect with you, the more you are inclined to do that &lt;em&gt;thing&lt;/em&gt;. For instance&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why do you wake up early in the morning and hit the Gym? 💪🏽 &lt;em&gt;You want to build a fitter body and beat the scale.&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;Why do you study late into the night? 🙇🏽‍♂️ &lt;em&gt;You want to ace that exam and make everyone proud.&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So you see, getting a strong &lt;strong&gt;why&lt;/strong&gt; would solve those 2 issues. But what about the third one?&lt;/p&gt;

&lt;h2&gt;
  
  
  The tool
&lt;/h2&gt;

&lt;p&gt;This is where the tool that I was talking comes into the picture. &lt;/p&gt;

&lt;p&gt;See, most of the time, the topic that we want to write about is fairly clear to us. For instance, let's say I want to write about &lt;strong&gt;developer productivity&lt;/strong&gt;. Now the issue is that, from here on, that topic can lead to hundreds of tangents. But once you sit down to think about it, very few come to your mind. And that leads to a lack of clarity which in turn leads to nothing ever being written.&lt;/p&gt;

&lt;p&gt;This is where I recently found myself using this &lt;strong&gt;FREE&lt;/strong&gt; tool &lt;a href="https://www.peppertype.ai/"&gt;peppertype.ai&lt;/a&gt;. It is basically an AI assistant that generates text based content based on the context that you provide. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dgHUiz92--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f74ufnb4ldgrwv02ve4k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dgHUiz92--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f74ufnb4ldgrwv02ve4k.png" alt="Screenshot 2021-08-20 at 7.11.52 PM" width="800" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically, you can use it for anything from generating &lt;strong&gt;Ad copies&lt;/strong&gt;, &lt;strong&gt;Product descriptions&lt;/strong&gt;, &lt;strong&gt;tweet ideas&lt;/strong&gt; etc. But in our case, we will be using it to generate blog ides.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--83lxHUbo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ymkz4um9rmsilio0l4vw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--83lxHUbo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ymkz4um9rmsilio0l4vw.png" alt="Screenshot 2021-08-20 at 7.13.40 PM" width="800" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I click on the "Blog ideas" Button and head to an interface that asks for a blog title and a description about what I am interested in writing about. As per my expectation, I fill in developer productivity and a brief description about it. And click &lt;strong&gt;Create blog ideas&lt;/strong&gt; and viola! 🪄&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rculSWsR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vwd4jkaktkpbq29wesx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rculSWsR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vwd4jkaktkpbq29wesx.gif" alt="article suggestions" width="800" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the list of the &lt;strong&gt;11 blog ideas&lt;/strong&gt; that the tool has generated for me which I can save for later to go back to. Which covers a broad range of articles related to the topic I chose. Also, do note that these topic suggestions are optimised for &lt;strong&gt;SEO&lt;/strong&gt; so that once you write out the article, it will rank high on google search. Also, you can always click on &lt;strong&gt;create more&lt;/strong&gt; in order to get some more suggestions. &lt;/p&gt;

&lt;p&gt;So go ahead, feel free to use the &lt;a href="https://www.peppertype.ai/"&gt;tool&lt;/a&gt; yourself to get ideas about the topics that you want to write about. But be judicious with your search and make sure that you save all the suggestions in the bookmarks because the free suggestions are capped at 10,000 worlds only. &lt;/p&gt;

&lt;p&gt;But remember, in the beginning I said that this solved my problem, but &lt;strong&gt;almost&lt;/strong&gt;. Because at the end of the day, an AI can only do so much and it is basically you who has to do the meat of the work and keep pushing until you reach your goals. So all the best with that. 🙌🏾&lt;/p&gt;

&lt;p&gt;Hope you liked this one, &lt;br&gt;
Cheers!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;PS:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F43sNgZ5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jpdl17k4e5ynqpciawot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F43sNgZ5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jpdl17k4e5ynqpciawot.png" alt="peppertype lifetime deal" width="800" height="461"&gt;&lt;/a&gt;&lt;br&gt;
If you end up liking the tool and are considering subscribing to the paid version, it's available as a subscription starting from 💰 &lt;strong&gt;USD 25&lt;/strong&gt; per month. &lt;br&gt;
But the good people at &lt;strong&gt;Peppertype&lt;/strong&gt; have made a 🎊&lt;strong&gt;LIFETIME DEAL&lt;/strong&gt;🎊 available for the product on &lt;strong&gt;Appsumo.com&lt;/strong&gt; starting from &lt;strong&gt;USD 39&lt;/strong&gt; for life! 🙌🏾. &lt;/p&gt;

&lt;h2&gt;
  
  
  Deal link
&lt;/h2&gt;

&lt;p&gt;Check out the deal link &lt;a href="https://appsumo.8odi.net/Vy6agM"&gt;here&lt;/a&gt;. Do note that the link is affiliate but you end up paying exactly the same. &lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>writing</category>
      <category>startup</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
