<?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>Forem: Talabi Ayomide</title>
    <description>The latest articles on Forem by Talabi Ayomide (@ayo_dev).</description>
    <link>https://forem.com/ayo_dev</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%2F869561%2F1e0e6145-b487-42d2-b16c-431ec0699929.jpg</url>
      <title>Forem: Talabi Ayomide</title>
      <link>https://forem.com/ayo_dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ayo_dev"/>
    <language>en</language>
    <item>
      <title>Understanding CSS Media Queries</title>
      <dc:creator>Talabi Ayomide</dc:creator>
      <pubDate>Mon, 11 Jul 2022 11:05:48 +0000</pubDate>
      <link>https://forem.com/ayo_dev/understanding-css-media-queries-3jmo</link>
      <guid>https://forem.com/ayo_dev/understanding-css-media-queries-3jmo</guid>
      <description>&lt;p&gt;Media queries are used to include a block of CSS properties only if a certain condition is true.&lt;br&gt;
when you want to modify your site depending on a device's general or specific characteristics and parameters, the CSS media query is what you need.&lt;br&gt;
In this guide, we would explain media queries like you are 5!&lt;br&gt;
Let's get started.&lt;/p&gt;

&lt;p&gt;You can think of media queries as a condition. If true, we do something, else we do something else.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Syntax&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A media query is composed of an optional media type and any number of media feature expressions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a media type?&lt;/strong&gt;&lt;br&gt;
This defines the broad category of a device for which the media query applies: all, print, screen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a media Feature?&lt;/strong&gt;&lt;br&gt;
Media features describe a specific characteristic of the user agent, output device, or environment eg height, prefers-color-scheme, width, etc.&lt;/p&gt;
&lt;h3&gt;
  
  
  Targeting media types
&lt;/h3&gt;

&lt;p&gt;Media types describe the general category of a given device. it can be targeted as seen below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;media&lt;/span&gt; &lt;span class="nt"&gt;screen&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt;//do&lt;/span&gt; &lt;span class="err"&gt;something&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;screen&lt;/strong&gt; in the above code is the media type.&lt;/p&gt;

&lt;h3&gt;
  
  
  Targeting media features
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12450px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;do&lt;/span&gt; &lt;span class="nt"&gt;something&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;max-width&lt;/strong&gt; in the above code is the media feature.&lt;/p&gt;

&lt;p&gt;Sometimes you may want to create a media query that depends on &lt;strong&gt;multiple conditions&lt;/strong&gt;. This is where the logical operators &lt;strong&gt;not, and, &amp;amp; only&lt;/strong&gt; come in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30em&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;orientation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;landscape&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;do&lt;/span&gt; &lt;span class="nt"&gt;something&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;min-width&lt;/strong&gt; and &lt;strong&gt;orientation&lt;/strong&gt; in the above code are the conditions that the media query depends on.&lt;/p&gt;

&lt;p&gt;To get a better understanding, we would be replicating the below hero section for both mobile and desktop screen sizes.&lt;/p&gt;

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

&lt;p&gt;Create an HTML file and name it whatever you want. I'm naming mine &lt;u&gt;index.html&lt;/u&gt;&lt;br&gt;
Create a CSS file and name it whatever you want. I'm naming mine &lt;u&gt;style.css&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;//index.html 
&lt;span class="nt"&gt;&amp;lt;section&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;'first-div'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Meet Celtic&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;A secret tool for the best analytic experience&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Track your goal and monitor your progress towards important goals/quotas&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;'#'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Get started&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;'#'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Request demo&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;'second-div'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;'image'&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;'www.google.com/image/celtic'&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code has created the required elements for the hero section. We won't focus on styling the elements. Let's use CSS to develop the layout.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;*,&lt;/span&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;margin&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;section&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;display&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;align-items&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-between&lt;/span&gt;
&lt;span class="n"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.image&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;320px&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 above code is well optimized and will display correctly on the desktop. But on smaller screens, the layout starts looking disorganized.&lt;br&gt;
The best option is to move the image to a different line entirely.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;Targeting&lt;/span&gt; &lt;span class="nt"&gt;screen&lt;/span&gt; &lt;span class="nt"&gt;sizes&lt;/span&gt; &lt;span class="nt"&gt;between&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt; &lt;span class="nt"&gt;and&lt;/span&gt; &lt;span class="err"&gt;450&lt;/span&gt;&lt;span class="nt"&gt;px&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;450px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nt"&gt;section&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.image&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&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;Changing flex-direction to a column when the screen size is 450px or below helps make our website responsive.&lt;br&gt;
And the image takes 100% of its size when the screen size is 450px or below.&lt;br&gt;
Yes, that's how easy it is!&lt;/p&gt;

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

&lt;p&gt;Media query is a CSS technique that uses the &lt;a class="mentioned-user" href="https://dev.to/media"&gt;@media&lt;/a&gt; rule to include a block of CSS properties only if a certain condition is true.&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Struggling With Context API ? You Are Not Alone.</title>
      <dc:creator>Talabi Ayomide</dc:creator>
      <pubDate>Mon, 04 Jul 2022 13:03:29 +0000</pubDate>
      <link>https://forem.com/ayo_dev/struggling-with-context-api-you-are-not-alone-20i</link>
      <guid>https://forem.com/ayo_dev/struggling-with-context-api-you-are-not-alone-20i</guid>
      <description>&lt;p&gt;State is an &lt;strong&gt;essential&lt;/strong&gt; part of our React application, hence, the need to pass to different components. state/data is passed top-down (parent to child) via &lt;strong&gt;props&lt;/strong&gt;. This is called &lt;strong&gt;PROP DRILLING&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%2Fylzg1p3zr6ompxsy0kyq.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%2Fylzg1p3zr6ompxsy0kyq.png" alt="Prop drilling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This method becomes complex as the application grows and as many components require different props.&lt;br&gt;
Things can get messy in a twinkle of an eye.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Context&lt;/strong&gt; provides a way to share values like these between components without having to pass a prop through every level of the tree.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;In this guide, we would talk about &lt;strong&gt;context API&lt;/strong&gt;, and its usage and build a mini-project ( a search application ) with it.&lt;br&gt;
Let's dive in.&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;Context is designed to share data that can be considered &lt;strong&gt;global&lt;/strong&gt; for a tree of React components, such as the current authenticated user, theme, etc.&lt;/p&gt;

&lt;p&gt;I am guessing your editor is already set up.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set up Context API
&lt;/h3&gt;

&lt;p&gt;First, we have to create a file called &lt;strong&gt;ResultContext.js&lt;/strong&gt; (feel free to name it whatever you want) and import the required hooks.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import React , { useContext , useState , createContext } from "react"&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create Context
&lt;/li&gt;
&lt;/ul&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="nx"&gt;ResultContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a &lt;strong&gt;"Provider"&lt;/strong&gt; and add {children} as a prop
&lt;/li&gt;
&lt;/ul&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ResultContextProvider&lt;/span&gt; &lt;span class="o"&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;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//state for results&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;results&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setResults&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;
&lt;span class="c1"&gt;//state for search Term&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;searchTerm&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSearchTerm&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Elon Musk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//create a function to fetch data&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getResults&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&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;X-API-Key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;REACT_APP_API_KEY&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://google
search3.p.rapidapi.com/api/v1/search&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c1"&gt;//set results to the results gotten from data fetched&lt;/span&gt;
    &lt;span class="nf"&gt;setResults&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;results&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;ul&gt;
&lt;li&gt;Return Context.Provider inside the previously created Provider and set &lt;strong&gt;value&lt;/strong&gt; to the props to be passed.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="nc"&gt;ResultContext&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getResults&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;searchTerm&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSearchTerm&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;
        &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;ResultContext&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;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are done with setting up our context file. &lt;strong&gt;In summary:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We created context using the &lt;strong&gt;createContext()&lt;/strong&gt; hook.&lt;/li&gt;
&lt;li&gt;We created  A &lt;strong&gt;"provider"&lt;/strong&gt; and passed {children} as a prop and returns ResultContext.Provider. &lt;/li&gt;
&lt;li&gt;We fetched data and set the &lt;strong&gt;results state&lt;/strong&gt; to the data fetched.&lt;/li&gt;
&lt;li&gt;We returned a ResultContext.Provider and set value to the states we want to pass as props into other components. Whatever we pass into the value prop will be available throughout our app.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Wrap the App component with the Provider
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&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&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;ResultContextProvider&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;./context/ResultContextProvider&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;createRoot&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-dom/client&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;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&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;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//wrap &amp;lt;App /&amp;gt; with Provider to make state available through app&lt;/span&gt;
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ResultContextProvider&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
               &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Router&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;/ResultContextProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Consume the props
&lt;/h3&gt;

&lt;p&gt;Now the state/Props are available throughout the App, we now need to consume them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Import the required Hooks &lt;br&gt;
&lt;code&gt;import React, { useEffect, useContext } from 'react'&lt;/code&gt;&lt;br&gt;
The &lt;strong&gt;useContext&lt;/strong&gt; hook is used to get the props from the context.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Import the context&lt;br&gt;
&lt;code&gt;import { ResultContext } from '../context/ResultContext'&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get the props from the context using &lt;strong&gt;useContext&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;//component for search&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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="nx"&gt;useState&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;ResultContext&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;../context/ResultContext&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;Search&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//get prop from context&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;setSearchTerm&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ResultContext&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;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;//change the value of text throughout our app&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setSearchTerm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;text&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;div&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;div&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;input&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;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;
        &lt;span class="na"&gt;onChange&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="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&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="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;text&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&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;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&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="nf"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;(&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;x&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;)&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;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  )
}

export default Search;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;//component displaying result&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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="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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useResultContext&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;../context/ResultContext&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;News&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;getResults&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;searchTerm&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ResultContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;searchTerm&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;getResults&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;searchTerm&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;div&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;results&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(({&lt;/span&gt; &lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;index&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="si"&gt;}&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;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;target&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"_blank"&lt;/span&gt; &lt;span class="na"&gt;rel&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"noreferrer"&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;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;substring&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="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;link&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;p&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;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;title&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;p&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;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;description&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;p&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;a&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;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&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;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;News&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&lt;em&gt;The main takeaways from this article include the following:&lt;/em&gt;&lt;br&gt;
The React Context API is designed for prop drilling&lt;/p&gt;

&lt;p&gt;This example is fairly simple and I hope you’ve been able to understand how to handle State in React using the context API.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>react</category>
    </item>
    <item>
      <title>Are You A React js Developer? These Are Reasons You Should Learn Next js.</title>
      <dc:creator>Talabi Ayomide</dc:creator>
      <pubDate>Mon, 27 Jun 2022 14:30:59 +0000</pubDate>
      <link>https://forem.com/ayo_dev/are-you-a-react-js-developer-these-are-reasons-you-should-learn-next-js-oh7</link>
      <guid>https://forem.com/ayo_dev/are-you-a-react-js-developer-these-are-reasons-you-should-learn-next-js-oh7</guid>
      <description>&lt;p&gt;Hello, I am guessing you must have heard the buzzword &lt;strong&gt;"NEXT JS"&lt;/strong&gt;. Yeah, I thought as much.&lt;br&gt;
&lt;strong&gt;In this guide, we are going to focus on what Next js is, the difference between it and React, reasons to use and how to get started.&lt;/strong&gt;&lt;br&gt;
I hope you are excited, because I am. Let's dive in!&lt;/p&gt;
&lt;h1&gt;
  
  
  What is Next js?
&lt;/h1&gt;

&lt;p&gt;In a few words, it is simply The &lt;strong&gt;React Framework for Production&lt;/strong&gt;.&lt;br&gt;
Next.js is a flexible React framework that gives you &lt;strong&gt;building blocks&lt;/strong&gt; to create fast web applications.&lt;/p&gt;

&lt;p&gt;React on the other hand is a &lt;strong&gt;&lt;u&gt;Library&lt;/u&gt;&lt;/strong&gt;, meaning React provides helpful functions to build UI but leaves it up to the developer where the function is to be used.&lt;/p&gt;

&lt;p&gt;Developers need to spend time configuring tools and rewriting solutions for common application requirements in React compared to Next.js which handles the tooling and configuration needed for React and provides additional features and optimizations for your application.&lt;/p&gt;
&lt;h1&gt;
  
  
  FEATURES OF NEXT JS
&lt;/h1&gt;
&lt;h3&gt;
  
  
  PAGES
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;- Pages with Dynamic Routes&lt;/strong&gt;&lt;br&gt;
Next.js supports pages with dynamic routes. For example, if you create a file called pages/about.js, then it will be accessible at /about.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Pre-rendering&lt;/strong&gt;&lt;br&gt;
By default, Next.js pre-renders every page. This means that Next.js generates HTML for each page in advance, instead of having it all done by client-side JavaScript. &lt;strong&gt;This results in better performance and SEO.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next.js has two forms of pre-rendering:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Static Generation&lt;/li&gt;
&lt;li&gt;Server-side Rendering
The difference is in when it generates the HTML for a page._&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Static Generation:&lt;/strong&gt; The HTML is generated at build time and will be reused on each request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server-side Rendering:&lt;/strong&gt; The HTML is generated on each request.&lt;/p&gt;

&lt;p&gt;If you can pre-render the page ahead of the user's request, then use Static Generation.&lt;/p&gt;

&lt;p&gt;Data fetching in Next.js allows you to render your content in different way :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;getStaticPaths&lt;/strong&gt;&lt;br&gt;
Next.js will statically pre-render all the paths specified by getStaticPaths. You should use getStaticPaths if you’re statically pre-rendering pages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;getStaticProps&lt;/strong&gt;&lt;br&gt;
If you export a function called getStaticProps (Static Site Generation) from a page, Next.js will pre-render this page at build time using the props returned by getStaticProps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;getServerSideProps&lt;/strong&gt;&lt;br&gt;
You should use getServerSideProps only if you need to render a page whose data must be fetched at the request time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Client-side data fetching&lt;/strong&gt;&lt;br&gt;
Client-side data fetching is useful when the content of your pages needs to update frequently. Unlike the server-side rendering APIs, you can use client-side data fetching at the component level.&lt;/p&gt;
&lt;h3&gt;
  
  
  BUILT-IN CSS SUPPORT
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Adding Component-Level CSS&lt;/strong&gt;&lt;br&gt;
Next.js supports CSS Modules using the [name].module.css file naming convention.&lt;br&gt;
CSS Modules locally scope CSS by automatically creating a unique class name. This allows you to use the same CSS class name in different files without worrying about collisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding a Global Stylesheet&lt;/strong&gt;&lt;br&gt;
To add a stylesheet to your application, import the CSS file within pages/_app.js. These styles (styles.css) will apply to all pages and components in your application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sass Support&lt;/strong&gt;&lt;br&gt;
Next.js allows you to import Sass using both the .scss and .sass extensions. You can use component-level Sass via CSS Modules and the .module.scss or .module.sass extension.&lt;br&gt;
Before you can use Next.js' built-in Sass support, be sure to install sass&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CSS-in-JS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;&lt;br&gt;
It's possible to use any existing CSS-in-JS. The inline style is the simplest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    function Hi() {
      return &amp;lt;p style={{ color: 'red' }}&amp;gt;hi there&amp;lt;/p&amp;gt;
    }
    export default Hi;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  LAYOUTS
&lt;/h3&gt;

&lt;p&gt;The React model allows us to construct a page from a series of components. Many of these components are often reused between pages. For example, you might have the same footer on every page.&lt;/p&gt;

&lt;p&gt;If you only have one layout for your entire application, you can create a Custom Layout and wrap your application with the layout. Since the component is re-used when changing pages, its component state will be preserved&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// components/layout.js

import Navbar from './navbar'
import Footer from './footer'

export default function Layout({ children }) {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;Navbar /&amp;gt;
      &amp;lt;main&amp;gt;{children}&amp;lt;/main&amp;gt;
      &amp;lt;Footer /&amp;gt;
    &amp;lt;/&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Layout from '../components/layout'

export default function MyApp({ Component, pageProps }) {
  return (
    &amp;lt;Layout&amp;gt;
      &amp;lt;Component {...pageProps} /&amp;gt;
    &amp;lt;/Layout&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  IMAGE COMPONENT AND IMAGE OPTIMIZATION
&lt;/h3&gt;

&lt;p&gt;The Next.js Image component, next/image, is an extension of the HTML element. It has built-in performance optimizations to help you &lt;strong&gt;achieve good Core Web Vitals which affect google ranking&lt;/strong&gt;.&lt;br&gt;
To add an image to your application, import the next/image component:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import Image from 'next/image'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Image Sizing&lt;/strong&gt;&lt;br&gt;
One of the ways that images most commonly hurt performance is when the &lt;u&gt;&lt;em&gt;image pushes other elements around on the page as it loads in&lt;/em&gt;&lt;/u&gt;. This performance problem has its own Core Web Vital, called &lt;strong&gt;Cumulative Layout Shift.&lt;/strong&gt;&lt;br&gt;
The way to avoid this issue is to always size your images. This allows the browser to reserve precisely enough space for the image before it loads.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;next/image is designed to avoid Layout shift and must be sized in one of three ways:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Automatically, using a static import&lt;/li&gt;
&lt;li&gt;Explicitly, by including a width and height property&lt;/li&gt;
&lt;li&gt;Implicitly, by using &lt;strong&gt;layout="fill"&lt;/strong&gt; which causes the image to expand to fill its parent element.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  FONT OPTIMIZATION
&lt;/h3&gt;

&lt;p&gt;Since version 10.2, Next.js has built-in web font optimization.&lt;br&gt;
By default, Next.js will automatically inline font CSS at build time, &lt;strong&gt;reducing the time taken to fetch font declarations.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;&lt;br&gt;
To add a web font to your Next.js application, add the font to a Custom Document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// pages/_document.js

import Document, { Html, Head, Main, NextScript } from 'next/document'

function MyDocument Document {
    return (
      &amp;lt;Html&amp;gt;
        &amp;lt;Head&amp;gt;
          &amp;lt;link
            href="https://fonts.googleapis.com/css2 family=Inter&amp;amp;display=optional" rel="stylesheet"/&amp;gt;
        &amp;lt;/Head&amp;gt;
        &amp;lt;body&amp;gt;
          &amp;lt;Main /&amp;gt;
          &amp;lt;NextScript /&amp;gt;
        &amp;lt;/body&amp;gt;
      &amp;lt;/Html&amp;gt;
    )
  }
export default MyDocument
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  STATIC FILE SERVING
&lt;/h3&gt;

&lt;p&gt;Next.js serves static files, like images, under a folder called public in the root directory. Files inside public can then be referenced.&lt;/p&gt;

&lt;p&gt;For example, if you add an image to public/image.png, the following code will access the image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Image from 'next/image'
function Avatar() {
  return &amp;lt;Image src="/me.png" alt="img" width="64" height="64" /&amp;gt;
}
export default Avatar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  FAST REFRESH
&lt;/h3&gt;

&lt;p&gt;Fast Refresh is a Next.js feature that gives you &lt;strong&gt;instantaneous feedback on edits&lt;/strong&gt; made to your React components. It is enabled by default in all Next.js applications on 9.4 or newer.&lt;/p&gt;

&lt;p&gt;With Next.js Fast Refresh enabled, most edits should be visible within a second, without losing component state.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you edit a file that only exports React component(s), Fast Refresh will update the code only for that file and re-render your component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you edit a file with exports that aren't React components, Fast Refresh will re-run both that file and the other files importing it. So if both Button.js and Card.js import Nav.js, editing Nav.js will update both components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, if you edit a file that's imported by files outside of the React tree, Fast Refresh will fall back to doing a full reload.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  TYPESCRIPT
&lt;/h3&gt;

&lt;p&gt;Next.js provides an &lt;strong&gt;integrated TypeScript experience,&lt;/strong&gt; including &lt;u&gt;zero-configuration setup and built-in types&lt;/u&gt; for Pages, APIs, and more.&lt;/p&gt;

&lt;p&gt;You can create a TypeScript project with &lt;strong&gt;create-next-app using the --ts, --typescript flag&lt;/strong&gt; like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app@latest --ts
# or
yarn create next-app --typescript
# or
pnpm create next-app --ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ENVIRONMENT VARIABLES
&lt;/h3&gt;

&lt;p&gt;Next.js comes with &lt;strong&gt;built-in support for environment variables&lt;/strong&gt; from Next.js versions 9.4 and up, which allows you to do the following:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Loading Environment Variables&lt;/strong&gt;&lt;br&gt;
Next.js has built-in support for loading environment variables from .env.local into process.env.&lt;/p&gt;

&lt;p&gt;An example .env.local:&lt;br&gt;
DB_URL=localhost&lt;br&gt;
DB_USER=myuser&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// pages/index.js
export async function getStaticProps() {
  const db = await myDB.connect({
    host: process.env.DB_URL,
    username: process.env.DB_USER
  })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ROUTING
&lt;/h3&gt;

&lt;p&gt;Next.js has a file-system based router built on the concept of pages.&lt;/p&gt;

&lt;p&gt;When a file is added to the pages directory, &lt;strong&gt;it's automatically available as a route.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The files inside the pages directory can be used to define the most common patterns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Index routes&lt;/strong&gt;&lt;br&gt;
The router will automatically route files named index to the root of the directory.&lt;/p&gt;

&lt;p&gt;pages/index.js → /&lt;br&gt;
pages/blog/index.js → /blog&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nested routes&lt;/strong&gt;&lt;br&gt;
The router supports nested files. If you create a nested folder structure, files will automatically be routed in the same way still.&lt;/p&gt;

&lt;p&gt;pages/blog/first-post.js → /blog/first-post&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linking between pages&lt;/strong&gt;&lt;br&gt;
The Next.js &lt;strong&gt;router&lt;/strong&gt; allows you to do client-side route transitions between pages, similar to a single-page application.&lt;/p&gt;

&lt;p&gt;A React component called &lt;strong&gt;&lt;u&gt;Link&lt;/u&gt;&lt;/strong&gt; is provided to do this client-side route transition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Link from 'next/link'

function Home() {
  return (
    &amp;lt;ul&amp;gt;
      &amp;lt;li&amp;gt;
        &amp;lt;Link href="/"&amp;gt;
          &amp;lt;a&amp;gt;Home&amp;lt;/a&amp;gt;
        &amp;lt;/Link&amp;gt;
      &amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
  )
}
export default Home
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;next/link can cover most of your routing needs, but you can also do client-side navigations without it by using &lt;strong&gt;next/router.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The following example shows how to do basic page navigations with useRouter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useRouter } from 'next/router'

export default function ReadMore() {
  const router = useRouter()

  return (
    &amp;lt;button onClick={() =&amp;gt; router.push('/about')}&amp;gt;
      Click here to read more
    &amp;lt;/button&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  API ROUTES
&lt;/h3&gt;

&lt;p&gt;Any file inside the folder pages/api is mapped to /api/* and will be treated as an &lt;strong&gt;API endpoint&lt;/strong&gt; instead of a page.&lt;/p&gt;

&lt;p&gt;For example, the following API route pages/api/user.js returns a json response with a status code of 200:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function handler(req, res) {
  res.status(200).json({ name: 'John Doe' })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  NEXT.JS ADVANTAGES
&lt;/h3&gt;

&lt;p&gt;React and Next.js both provide great developer experiences in their own way. But why use Next.js and not other frameworks for React? It depends on the production requirements and medium/long-term goals. Below are some advantages.&lt;/p&gt;

&lt;p&gt;Speed&lt;br&gt;
Fast rendering&lt;br&gt;
Built-in CSS support&lt;br&gt;
Better image optimization&lt;br&gt;
SEO&lt;br&gt;
ESLint compatible&lt;br&gt;
Easy customization and deployment&lt;br&gt;
API support&lt;/p&gt;

&lt;h3&gt;
  
  
  RESOURCES TO HELP YOU GET STARTED
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://nextjs.org/docs/getting-started"&gt;Official Docs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=CMx51wpd7g4&amp;amp;t=206s"&gt;Build a website with Next js&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=mTz0GXj8NN0&amp;amp;t=1804s"&gt;Next js crash course&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Get Up And Running With The useEffect Hook.</title>
      <dc:creator>Talabi Ayomide</dc:creator>
      <pubDate>Tue, 21 Jun 2022 08:46:12 +0000</pubDate>
      <link>https://forem.com/ayo_dev/get-up-and-running-with-the-useeffect-hook-3481</link>
      <guid>https://forem.com/ayo_dev/get-up-and-running-with-the-useeffect-hook-3481</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hooks&lt;/strong&gt; are new features incorporated into React 16.8. and the newer versions. They basically help you use React features without writing a class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In this guide, we are going to cover why this hook exists and how to use it in React.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you started your React journey before version 16.8, then you have to unlearn lifecycle methods and instead think in effects.&lt;/p&gt;

&lt;p&gt;The useEffect hook lets us express different kinds of &lt;strong&gt;side effects&lt;/strong&gt; after a component renders. In case you are wondering what side effects are, relax, you will understand in a second.&lt;/p&gt;

&lt;p&gt;Side effects are unpredictable actions performed with the "outside world."&lt;em&gt;&lt;u&gt; Data fetching, setting up a subscription, and manually changing the DOM in React components&lt;/u&gt;&lt;/em&gt; are all examples of side effects. Regardless of knowing what this term means, you have most likely used it.&lt;/p&gt;

&lt;p&gt;There are two common kinds of side effects in React components: those that don’t require cleanup, and those that do.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Side Effects Without Cleanup&lt;/strong&gt;&lt;br&gt;
Network requests, manual DOM mutations, and logging are common examples of effects that don’t require a cleanup. We can run them and immediately forget about them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Side Effect With Cleanup&lt;/strong&gt;&lt;br&gt;
Some effects require cleanup &lt;strong&gt;to reduce memory leaks.&lt;/strong&gt;&lt;br&gt;
Timeouts, subscriptions, event listeners, and other effects that are no longer needed should be disposed.&lt;br&gt;
This is done by &lt;strong&gt;&lt;em&gt;including a return function&lt;/em&gt;&lt;/strong&gt; at the end of the useEffect Hook.&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%2Fdbckjhrwatjfwi97cst2.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%2Fdbckjhrwatjfwi97cst2.png" alt="cleanup"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;useEffect is a tool that lets us interact with the external world but does not affect the rendering or performance of the component that it's in. React enables multiple useEffect instances inside a React functional component. The code can be broken down into multiple Hooks containing logically related code in a single function.&lt;/p&gt;

&lt;p&gt;By using this Hook, you tell React that your component needs to do something after render. React will remember the function you passed (we’ll refer to it as our “effect”), and call it later after performing the DOM updates.&lt;/p&gt;

&lt;p&gt;It is a combination of componentDidMount, componentDidUpdate, and componentWillUnmount lifecycle methods in class-based components.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why useEffect is defined inside a component?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;“useEffect” function is defined inside the component so that the variables and the functions defined inside the components can be accessed directly. If you are familiar with closures in JavaScript, you will probably be having an "aha!" moment now. And if you don't, it is not a problem. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closures&lt;/strong&gt; are functions that are nested in other functions and simply allows variables outside of the scope of a function to be accessed. It takes advantage of the concept of Closure to provide access to the local functions and variables defined inside a function.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How to use the useEffect hook&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;We import useEffect from "react"&lt;/li&gt;
&lt;li&gt;We call it above the returned JSX in our component&lt;/li&gt;
&lt;li&gt;We pass it &lt;strong&gt;&lt;u&gt;two arguments&lt;/u&gt;&lt;/strong&gt;: a function and an array
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect } from "react";

function Counter() {
  const [count, setCount] = useState(0);
  const [calculation, setCalculation] = useState(0);

  useEffect(() =&amp;gt; {
    setCalculation(() =&amp;gt; count * 2);
    console.log(calculation);
  }, [count]); // &amp;lt;- add the count variable here

  return (
    &amp;lt;&amp;gt;
      &amp;lt;p&amp;gt;Count: {count}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount((c) =&amp;gt; c + 1)}&amp;gt;+&amp;lt;/button&amp;gt;
      &amp;lt;p&amp;gt;Calculation: {calculation}&amp;lt;/p&amp;gt;
    &amp;lt;/&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function passed to useEffect is a &lt;strong&gt;callback function&lt;/strong&gt; which will be called after the component DOM renders. The side Effects are performed inside this function.&lt;/p&gt;

&lt;p&gt;The second argument is an array, called the dependencies array. This array includes all of the values the side effect relies on. What this array will do is it will check and see if a value has changed between renders. If so, it will execute our use effect function again. We can optionally pass dependencies to useEffect in this array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. No dependency passed:&lt;/strong&gt;&lt;br&gt;
useEffect(() =&amp;gt; {&lt;br&gt;
  //Runs on every render&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. An empty array:&lt;/strong&gt;&lt;br&gt;
useEffect(() =&amp;gt; {&lt;br&gt;
  //Runs only on the first render&lt;br&gt;
}, []);&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. State values passed into array:&lt;/strong&gt;&lt;br&gt;
useEffect(() =&amp;gt; {&lt;br&gt;
  //Runs on the first render&lt;br&gt;
  //And any time any dependency value changes&lt;br&gt;
}, [state]);&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;useEffect is a tool that lets us interact with the external world but does not affect the rendering or performance of the component that it's in.&lt;br&gt;
By using this Hook, you tell React that your component needs to do something after render. React will remember the function you passed, and call it later after performing the DOM updates.&lt;/p&gt;

&lt;p&gt;It is a combination of componentDidMount, componentDidUpdate, and componentWillUnmount lifecycle methods in class-based components.&lt;br&gt;
We pass &lt;strong&gt;&lt;u&gt;two arguments&lt;/u&gt;&lt;/strong&gt;: a function and an array into a useEffect hook.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
