<?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: John Rasine Irem</title>
    <description>The latest articles on DEV Community by John Rasine Irem (@eyesaidyo).</description>
    <link>https://dev.to/eyesaidyo</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%2F907834%2F53afa5cd-8e92-403d-9b73-cad019dd589d.jpeg</url>
      <title>DEV Community: John Rasine Irem</title>
      <link>https://dev.to/eyesaidyo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eyesaidyo"/>
    <language>en</language>
    <item>
      <title>Tailwind CSS or Styled Components?</title>
      <dc:creator>John Rasine Irem</dc:creator>
      <pubDate>Sat, 29 Jun 2024 11:30:56 +0000</pubDate>
      <link>https://dev.to/eyesaidyo/tailwind-css-or-styled-components-1dj3</link>
      <guid>https://dev.to/eyesaidyo/tailwind-css-or-styled-components-1dj3</guid>
      <description>&lt;p&gt;The world of front-end development is vast as we all know and it consists of many ways to solve different problems, one of which is styling with CSS. In my years using React predominantly for building UI components, various approaches to styling have appealed to me and in this article, I would like to make a case for two of my favorites. These two technologies solve the issue of styling components with CSS from two different points of view, my aim here is to present you with adequate information to make a sound decision as you pick your poison.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Case For Tailwind CSS
&lt;/h2&gt;

&lt;p&gt;Tailwind is a CSS framework that simplifies styling your components into declaring some already-prepared class names. These class names contain trusty, well-tested style declarations that translate well into any component you are building. You can get a breakdown of these class names in their documentation (which is excellent by the way!) &lt;a href="https://tailwindcss.com/docs"&gt;here&lt;/a&gt;.&lt;br&gt;
Here is a simple code-snippet to explain how this works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p class="text-lg font-medium"&amp;gt;
        “Tailwind CSS is the only framework that I've seen scale
        on large teams. It’s easy to customize, adapts to any design,
        and the build size is tiny.”
      &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the snippet above, the class names "text-lg" and "font-medium" are specifically provided by the CSS framework under the hood so you do not need to write out your own style declarations all you need do is state a class name they have already provided! For example, "text-lg" translates under the hood to:&lt;br&gt;
&lt;code&gt;font-size: 1.125rem; /* 18px */&lt;br&gt;
line-height: 1.75rem; /* 28px */&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;As you can see, this approach to writing CSS simplifies things a lot in the following ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It limits the amount of CSS files you need to make and removes the need for writing lengthy style declarations.&lt;/li&gt;
&lt;li&gt;You can see both your components and the styles without the need to go back and forth between files.&lt;/li&gt;
&lt;li&gt;This is much quicker to write and you can churn out components in record time once you know the docs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you need a project done quickly, especially if said project is concise, Tailwind would probably be my recommendation. It is lightweight, easy to use, and set up. The major drawback would be readability especially if it contains a lot of class names; you could run into some issues debugging especially if your knowledge of core CSS isn't at a great level.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Case for Styled Components
&lt;/h2&gt;

&lt;p&gt;If you have ever built large projects with lots of moving parts and CSS, I'm sure you can't stress enough the importance of separating concerns to avoid style clashes. As codebases get larger, debugging gets more difficult. In such a scenario, you'd need a CSS solution that allows you to get meticulous about keeping certain style declarations fixed only to the scope of a particular component and hidden from the global context of your styling.&lt;br&gt;
This is where Styled Components comes in. It is a CSS-in-JS solution to styling that enables you to write CSS right inside your JS component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Button = styled.a`
  background: transparent;
  border-radius: 3px;
  border: 1px solid var(--accent-color);
  color: var(--accent-color);
  display: inline-block;
  margin: 0.5rem 1rem;
  padding: 0.5rem 0;
  transition: all 200ms ease-in-out;
  width: 11rem;

  &amp;amp;:hover {
    filter: brightness(0.85);
  }

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

&lt;/div&gt;



&lt;p&gt;In the above code block, we see a component "Button" being cast as an anchor tag from the Styled Components library. This special anchor tag and its underlying style declarations are what gets rendered wherever the &lt;code&gt;&amp;lt;/Button&amp;gt;&lt;/code&gt; component is declared. However, what we don't see happening under the hood is that this component also has a unique class name assigned to it to enhance its specificity; in a situation where we create this exact component elsewhere, that new copy that is created will have its own unique class name created by Styled Components thus making every component we create unique. It is particularly difficult to have clashes using this approach.&lt;br&gt;
The drawbacks to this method include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It could be slow and tedious to write.&lt;/li&gt;
&lt;li&gt;There is plenty of boilerplate code involved, making your project more bulky than necessary&lt;/li&gt;
&lt;li&gt;It is not as performant as Tailwind&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In conclusion, there is no one-size-fits-all solution to writing CSS, there isn't a silver bullet either. These are my go-to approaches to solving most styling needs across all the projects I've worked on. I hope I've provided enough information for you to make a choice you like.&lt;/p&gt;

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

&lt;p&gt;(PS: Stick around if you want to hear about why I love React and the HNG internship I'm currently enrolled in :) )&lt;/p&gt;

&lt;h2&gt;
  
  
  PS
&lt;/h2&gt;

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

&lt;p&gt;I've been writing React for about 2 years now and it is undoubtedly my favorite front-end library. A lot of factors come into place to make this so; there is a large, wholesome community of developers ready to help on forums and social media; the documentation is amazing and helps you understand it quickly and easily; last, but not least, it is the choice front-end technology at HNG. This makes things easier for me as it is right within my wheelhouse and I can get straight into building things with great engineers.&lt;br&gt;
HNG Internships is an awesome initiative that brings thousands of developers together to work on challenges and build software together, making for a fast-paced, fun, vibrant, and unique learning experience. I have been a part of it for a couple of years and gleaned a lot of knowledge and also added some great projects to my portfolio. I hope to become a finalist this year for the first time, hopefully, I can hang on this time as the pressure gets "werser" (lol). If you would like to know more about the amazing work done at HNG internships, you can do so &lt;a href="https://hng.tech/internship"&gt;here&lt;/a&gt;. If you need to hire freelance talents for any of your projects, HNG also has you covered and you can get more information &lt;a href="https://hng.tech/hire"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks so much for reading!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
    </item>
    <item>
      <title>Github Profile Finder Project: A Walkthrough</title>
      <dc:creator>John Rasine Irem</dc:creator>
      <pubDate>Mon, 09 Jan 2023 09:26:34 +0000</pubDate>
      <link>https://dev.to/eyesaidyo/github-profile-finder-project-a-walkthrough-51f4</link>
      <guid>https://dev.to/eyesaidyo/github-profile-finder-project-a-walkthrough-51f4</guid>
      <description>&lt;h2&gt;
  
  
  Part 1: The Basics
&lt;/h2&gt;

&lt;p&gt;So, it was the end of my second semester at AltSchool Africa and I had an exam project to create a site showing my github profile and details about my repositories. In this article, I will explain how I went about implementing this project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tooling
&lt;/h3&gt;

&lt;p&gt;As far as tooling goes, this project was made using Replit, which is an online IDE and I did this so I could work anywhere and on any device on my project. Replit comes with React tooling already set up (via Vite) so you can set up a new React project in seconds and install packages using the GUI.&lt;/p&gt;

&lt;h3&gt;
  
  
  Structure
&lt;/h3&gt;

&lt;p&gt;All of the code was initially written in a single App component to make it so that I could get a working prototype as quickly as possible. All refactoring will be done in a more advanced portion of this article.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;

&lt;p&gt;I identified the most important steps to get my project up and running to be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetching my account from the github API using the Fetch API.&lt;/li&gt;
&lt;li&gt;Creating some basic state to assign the fetch results to.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Fetching data from an API and setting that data to a state (using a setter function) will often reuquire the use of the &lt;code&gt;useEffect&lt;/code&gt; hook. This is done in order to avoid an infinite re-rendering cycle in React as the JSON objects fetched cannot be read as the same result even if they contain the exact same content.&lt;br&gt;
I hence created an asynchronus &lt;code&gt;getUser()&lt;/code&gt; function to handle all my API calls and promises. In that function, I implemented the fetch as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const totalRepos= await fetch(`https://api.github.com/users/eyesaidyo`)
    .then(res=&amp;gt;res.json())
    .then(data=&amp;gt;data.public_repos)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creating state to assign the data to went as follows:&lt;br&gt;
&lt;code&gt;const [currentPage, setCurrentPage]= useState('')&lt;/code&gt;&lt;br&gt;
This state is what will be used to track and change paginated data coming from the API.&lt;/p&gt;

&lt;p&gt;A second fetch was then implemented in the getUser function this time, to get the actual repositories and their data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(`https://api.github.com/users/eyesaidyo/repos?per_page=${reposPerPage}&amp;amp;page=${currentPage}`)
.then(res=&amp;gt;res.json())
    .then(res=&amp;gt;{
      toSetRepos(res)
      // console.log(res)
      toSetPageCount(Math.ceil(totalRepos/reposPerPage))
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;toSetRepos&lt;/code&gt; is a setter function that gets a repos array for whatever the current page searched from the API is.&lt;br&gt;
&lt;code&gt;toSetPageCount&lt;/code&gt; calculates the number of pages needed to accomodate all the repos in my profile based on a fixed &lt;code&gt;reposPerPage&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;To make sure that I am able to get a certain list of repos based on which page in the fetch request is specified(&lt;code&gt;currentPage&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(()=&amp;gt;{
getUser()
}, [currentPage])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, whenever the component is mounted or there is a change to &lt;code&gt;currentPage&lt;/code&gt; via a setter function, my &lt;code&gt;getUser&lt;/code&gt; function runs.&lt;/p&gt;

&lt;p&gt;In order to display the repos, a Cards component was made:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const Cards=({repos})=&amp;gt;{

    return (
      &amp;lt;div&amp;gt;
        {repos.map((repo)=&amp;gt;{
        return(
          &amp;lt;Link className='repo-item-link' to={repo.name} key={repo.id}&amp;gt;
          &amp;lt;h3 className='repo-item' &amp;gt;{repo.name}&amp;lt;/h3&amp;gt;
            &amp;lt;/Link&amp;gt;
        )
        })}
        &amp;lt;/div&amp;gt;
    )
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, each repo item on the &lt;code&gt;currentPage&lt;/code&gt; will be rendered as &lt;code&gt;Link&lt;/code&gt; components which link to a new pathway, &lt;code&gt;repo.name&lt;/code&gt; that will in turn show more specific details partaining to the particular repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Routing
&lt;/h3&gt;

&lt;p&gt;The first thing is to import &lt;code&gt;Routes&lt;/code&gt; and &lt;code&gt;Route&lt;/code&gt; from &lt;code&gt;react-router-dom&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Routes&lt;/code&gt; acts as a container for each individual &lt;code&gt;Route&lt;/code&gt; and what it links &lt;code&gt;to&lt;/code&gt;.Note that &lt;code&gt;Route&lt;/code&gt; needs a &lt;code&gt;path&lt;/code&gt; property and an &lt;code&gt;element&lt;/code&gt; property. &lt;code&gt;path&lt;/code&gt; specifies the directory the webpage goes to in relation to its homepage or parent page. &lt;code&gt;element&lt;/code&gt; specifies a component to be displayed based on what directory the webpage is in. An example is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Routes&amp;gt;
        &amp;lt;Route path='/' element={&amp;lt;Nav/&amp;gt;}&amp;gt;
          &amp;lt;Route index element={&amp;lt;Home/&amp;gt;}/&amp;gt;
        &amp;lt;/Route&amp;gt;
&amp;lt;Routes&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I created a &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt; for each repository &lt;code&gt;Link&lt;/code&gt; (existing in the &lt;code&gt;Cards&lt;/code&gt; component) by using the &lt;code&gt;map&lt;/code&gt; function and looping through the state that is &lt;code&gt;repos&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
            repos.map(repo=&amp;gt;{
          return(
           &amp;lt;Route path={`/${repo.name}`} key={repo.id}               element={&amp;lt;Card 
          name={repo.name}
          forks={repo.forks}
          visibility={repo.visibility}              
          createdAt={repo.created_at}  
          language={repo.language}                                           watchers={repo.watchers}
          url={repo.html_url}
                                                                                /&amp;gt;}&amp;gt;
           &amp;lt;/Route&amp;gt;

          )
          })}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A route was also created to show a &lt;code&gt;&amp;lt;NotFound/&amp;gt;&lt;/code&gt; component anytime the user goes to a wrong directory (&lt;code&gt;*&lt;/code&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Route path='*' element={&amp;lt;NotFound/&amp;gt;}&amp;gt; &amp;lt;/Route&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pagination
&lt;/h3&gt;

&lt;p&gt;As things stand currently, this webpage can only display one small piece of the data fetched from the API at a time, This is because the fetch is paginated and only serves a few repos at a time (&lt;code&gt;reposPerPage&lt;/code&gt;) on whatever the &lt;code&gt;currentPage&lt;/code&gt; is. &lt;br&gt;
We need a way to dynamically set the currentPage to whatever we want; this is where pagination comes in  .&lt;br&gt;
In this project, I created my own basic pagination without any external libraries. My general idea was to use the calculated &lt;code&gt;pageCount&lt;/code&gt; gotten from the following snippet in the &lt;code&gt;getUser&lt;/code&gt; function: &lt;code&gt;toSetPageCount(Math.ceil(totalRepos/reposPerPage))&lt;/code&gt;; this &lt;code&gt;pageCount&lt;/code&gt; lets me know the total number of pages I'd need to accomodate all the repositories in my profile. I would then generate a button representing each page and assign an &lt;code&gt;onClick()&lt;/code&gt; which calls the &lt;code&gt;setCurrentPage&lt;/code&gt; function. Of course, showing every single button at the same time could make the UI bloated so I decided to show only 5 buttons at a time and then make a 'prev' and 'next' button to show the previous or the next 5 buttons if any. This previous and next buttons were set to disable at the beginning and at the end of available pages.&lt;br&gt;
The one thing missing is a way to map through all the pages since the &lt;code&gt;pageCount&lt;/code&gt; is not an array. I generated the array using a &lt;code&gt;for&lt;/code&gt; loop as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getPagesArray=()=&amp;gt;{
    let ans=[];
    for(let i=1; i&amp;lt;=pageCount; i++){
      ans.push(i)
    }
    return ans;
  }
  const pagesArray=getPagesArray()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now armed with my &lt;code&gt;pagesArray&lt;/code&gt;, I can choose to display only a &lt;code&gt;slice()&lt;/code&gt; of it in order to show only &lt;code&gt;buttonsPerPage&lt;/code&gt; number of buttons at a time (mine is set to five).&lt;br&gt;
There is also state for &lt;code&gt;firstIndex&lt;/code&gt; and &lt;code&gt;lastIndex&lt;/code&gt; so I can use the prev and next buttons to show the next 5 and previous 5 buttons. This is how the code was written:&lt;br&gt;
&lt;/p&gt;

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

           pagesArray.slice(firstIndex, lastIndex).map((num,ind)=&amp;gt; 
          {
             return (
               &amp;lt;button
                 key={ind}
                 onClick={()=&amp;gt;{
           toSetCurrentPage(pagesArray.indexOf(num)+1)
                 }} 
              &amp;gt;{pagesArray.indexOf(num)+1}&amp;lt;/button&amp;gt;)
           }
         )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The prev and next buttons were written like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button
            className='pg-btn'
            disabled={firstIndex===0}
            onClick={()=&amp;gt;{
              toSetFirstIndex(firstIndex-buttonsPerPage+1 &amp;gt;=0?
                             firstIndex-buttonsPerPage:
                             null)

              toSetLastIndex(lastIndex=== pageCount?
                            lastIndex-(pageCount%buttonsPerPage):lastIndex-buttonsPerPage
                            )

            }}
            &amp;gt;prev&amp;lt;/button&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;&amp;lt;button
            className='pg-btn'
            disabled={lastIndex===pageCount || pageCount&amp;lt;buttonsPerPage}
            onClick={()=&amp;gt;{
              toSetFirstIndex(firstIndex+buttonsPerPage)

              toSetLastIndex(lastIndex+buttonsPerPage &amp;lt;=pageCount?lastIndex+buttonsPerPage:pageCount)

            }}
            &amp;gt;
        next
      &amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Part 2: Refactoring and Improvements
&lt;/h2&gt;

&lt;p&gt;The 2 main areas I wanted to refactor and improve were :&lt;br&gt;
-Change the pagination components state manager from &lt;code&gt;useState&lt;/code&gt; to &lt;code&gt;useReducer&lt;/code&gt;&lt;br&gt;
-Move the pagination component out of the &lt;code&gt;App&lt;/code&gt; component and make the state available to the &lt;code&gt;App&lt;/code&gt; component using the Context API&lt;br&gt;
It started up as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const INITIAL_STATE={
    pageCount:0,
    firstIndex:0,
    lastIndex:0,
    currentPage:1,
    repos:[]
  }
export const PaginationContext=createContext({
  ...INITIAL_STATE,
  toSetFirstIndex:()=&amp;gt;{},
  toSetLastIndex:()=&amp;gt;{},
  toSetCurrentPage:()=&amp;gt;{},
  toSetPageCount:()=&amp;gt;{},
  toSetRepos:()=&amp;gt;{}
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reducers need an intial state for when the hook is called so i created one. Also I included the main functionalities I wanted to access in the App component which are mostly setter functions.&lt;br&gt;
The context provider was created next which includes the &lt;code&gt;paginationReducer&lt;/code&gt; itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const PaginationProvider=({children})=&amp;gt;{


  const paginationReducer=(state, action)=&amp;gt;{
    const {type, payload}= action
    switch (type){
      case 'CHANGE_FIRST_INDEX':
        return {
          ...state,
          firstIndex:payload
        }
      case 'CHANGE_LAST_INDEX':
        return {
          ...state,
          lastIndex:payload
        }
      case 'change_page':
        return{
          ...state,
          currentPage:payload
        }
        case 'change_page_count':
        return{
          ...state,
          pageCount:payload
        }
        case 'change_repos':
        return{
          ...state,
          repos:payload
        }
      default:
        return state

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;useReducer&lt;/code&gt; is then called and all the setter functions were created in the same format as the &lt;code&gt;toSetFirstIndex&lt;/code&gt; below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [state, dispatch]= useReducer(paginationReducer, INITIAL_STATE)

  const toSetFirstIndex=(idx)=&amp;gt;{
    dispatch({type:'CHANGE_FIRST_INDEX', payload:idx})
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Part 3: New Features
&lt;/h2&gt;

&lt;p&gt;I added a &lt;code&gt;Search&lt;/code&gt; page which basically included a search bar with an &lt;code&gt;onChange&lt;/code&gt; handler. The handler's job is to fetch any profiles matching the value of the searchbox:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const handleChange=async (e)=&amp;gt;{
    if( e.target.value){
      await fetch(`https://api.github.com/users/${e.target.value}`)
      .then(res=&amp;gt;res.json())
      .then(res=&amp;gt;{
        if(res.status==404){
          setShowError(true)
        } else 
        { 
          setShowError(false)
          setName(res.name)
                  setImage(res.avatar_url)
      }})
     await fetch(`https://api.github.com/users/${e.target.value}/repos?per_page=${reposPerPage}&amp;amp;page=${currentPage}`)
       .then(res=&amp;gt;res.json())
      .then(res=&amp;gt;{

        setRepos(res)})
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the end if a repository is found to match what is in the searchbox, a div is displayed showing the name and profile picture of the user, also some  of the user's repositories are shown if the profile picture is clicked on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return(
    &amp;lt;div &amp;gt;

      &amp;lt;h1&amp;gt;search page&amp;lt;/h1&amp;gt;
      &amp;lt;input type='search' onChange={handleChange} /&amp;gt;
      {showError &amp;amp;&amp;amp;&amp;lt;h2&amp;gt;userNotFound&amp;lt;/h2&amp;gt;}
      &amp;lt;div className='search-result'&amp;gt;
      &amp;lt;img onClick={handleClick} className="search-img" src={image}/&amp;gt;
      &amp;lt;p&amp;gt;{name}&amp;lt;/p&amp;gt;
        {showRepos&amp;amp;&amp;amp;&amp;lt;Cards repos={repos}/&amp;gt; }
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;This was quite a challenging project at times despite how simple it looked on paper but I am glad i got it done. The final outcome &lt;br&gt;
can be found &lt;a href="https://eyesaidyo.netlify.app/" rel="noopener noreferrer"&gt;here&lt;/a&gt; and the repository of the project can be found &lt;a href="https://github.com/eyesaidyo/my-repos-2" rel="noopener noreferrer"&gt;here&lt;/a&gt;,&lt;br&gt;
Thanks a lot for reading!&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
  </channel>
</rss>
