<?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: Ifeoluwa Favour</title>
    <description>The latest articles on DEV Community by Ifeoluwa Favour (@iiphe).</description>
    <link>https://dev.to/iiphe</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%2F1004854%2Ff710f1aa-2ab5-4a3d-819c-6319dc04ed2a.png</url>
      <title>DEV Community: Ifeoluwa Favour</title>
      <link>https://dev.to/iiphe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iiphe"/>
    <language>en</language>
    <item>
      <title>How I Built A Github RepoSearch App Using Reactjs</title>
      <dc:creator>Ifeoluwa Favour</dc:creator>
      <pubDate>Tue, 10 Jan 2023 09:23:38 +0000</pubDate>
      <link>https://dev.to/iiphe/how-i-built-a-github-reposearch-app-using-reactjs-52kf</link>
      <guid>https://dev.to/iiphe/how-i-built-a-github-reposearch-app-using-reactjs-52kf</guid>
      <description>&lt;p&gt;&lt;em&gt;Let's get started.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  About the App
&lt;/h2&gt;

&lt;p&gt;RepoSearch App is simply a web App that Fetches Users' GitHub details and repository details. This is a project for my AltSchool Second Semester examination, and this is me sharing my process. .&lt;/p&gt;

&lt;p&gt;I built the App using React, which is a JavaScript library for building user interfaces. The React App displays list of user's  Repositories on GitHub, which routes to the details of each repository. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Task&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;_&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Implement an API fetch of your GitHub portfolio, show a page with a list of all your repositories on GitHub(the page should implement pagination for the repo list), and create another page showing data for a single repo clicked from the list of repos using nested routes while using all the necessary tools in react. Implement the proper SEO, Error Boundary (show a page to test the error boundary) and 404 pages. Good UI and Designs are important._&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The Page was built using;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Semantic HTML5&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ReactJs&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Process
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Setting up React&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To work with React for any project, the first thing to do is to create react application boilerplate using create-react-app&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-react-app my-app

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Installation of Some Dependencies Used&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cagpW_ht--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ho1fn7st8pgpdjsqleq0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cagpW_ht--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ho1fn7st8pgpdjsqleq0.jpg" alt="Image description" width="280" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before writing any line of codes in my App.js, i make sure to  install Error Boundary to wrap all my codes in for easy readability of my code errors.&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;ErrorBoundary FallbackComponent={ErrorFallback}&amp;gt;
       &amp;lt;App /&amp;gt;

      &amp;lt;/ErrorBoundary&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then on to the next...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Creating of Components&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This gives a start to my project. The next thing i did was create a folder called "components" and another one called "pages" in the src folder. &lt;br&gt;
Component is the base class for the React components defined as JavaScript classes. Then under Components i organized my work into different folders, for easy access, readability and reusability.&lt;br&gt;
Also under my pages i organized the pages i'll be working with. See below ;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q0ADuhcn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6ji9xpssli5s53g7u2j.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q0ADuhcn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6ji9xpssli5s53g7u2j.jpg" alt="Image description" width="243" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Fetching API&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then i implemented an API fetch for my GitHub repos search in my SearchBar.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const getRepos = async (val) =&amp;gt; {
    // condition that made sure that the fetch will only happen if the searchInput field is not empty
    if (searchInput) {
      const repos = await fetch(
        `https://api.github.com/users/${searchInput}/repos?per_page=8&amp;amp;page=${val}`
      );
      const data = await repos.json();
      setRepos(data);
    }
    return;
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also imported the necessary ReactHook i needed.&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;Then I created state variables inside my SearchBar.js to store the responses from the API fetch. The state will update as soon as the server sends the response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const SearchBar = () =&amp;gt; {
  const [searchInput, setSearchInput] = useState("");
  // I moved the repos and setRepos here from Result.js file
  const [repos, setRepos] = useState([]);

  const handleChange = (e) =&amp;gt; {
    setSearchInput(e.target.value);
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I created an async / await function called getRepos that made the API fetch request to the GitHub API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const getRepos = async (val) =&amp;gt; {
    // condition that made sure that the fetch will only happen if the searchInput field is not empty
    if (searchInput) {
      const repos = await fetch(
        `https://api.github.com/users/${searchInput}/repos?per_page=8&amp;amp;page=${val}`
      );
      const data = await repos.json();
      setRepos(data);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then i went ahead to render it&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;&amp;gt;
      &amp;lt;p className="paragraph"&amp;gt;Enter your github username below:&amp;lt;/p&amp;gt;
      &amp;lt;div className="search-bar" style={{ padding: "50px" }}&amp;gt;
        &amp;lt;input
          type="text"
          placeholder="search"
          value={searchInput}
          onChange={handleChange}
        /&amp;gt;
        {/* Call your getRepo function here instead of using useEffect */}
        &amp;lt;button className="search-button" onClick={() =&amp;gt; getRepos(1)}&amp;gt;
          Search
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;Results
        className="repos-list"
        name={searchInput}
        repos={repos}
        getRepos={getRepos}
      /&amp;gt;
    &amp;lt;/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Result.js file, i created a function called Results that getRepos once a particular GitHub username is being searched for in this format;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Results({ repos, name, getRepos }) {
  return (
    &amp;lt;div className="repos"&amp;gt;
      &amp;lt;h1 className="repo-header"&amp;gt;Repositories&amp;lt;/h1&amp;gt;
      &amp;lt;ul className="repo-container"&amp;gt;
        {/* here, i added repos to the condition. so the map will only happen if all condition are true */}
        {repos &amp;amp;&amp;amp;
          repos[0] &amp;amp;&amp;amp;
          repos.map((repo, i) =&amp;gt; (
            &amp;lt;a
              href={`https://github.com/${name}/${repo.name}`}
              key={i}
              target="_blank"
              rel="noreferrer"
            &amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then rendered it also.&lt;/p&gt;

&lt;p&gt;Halfway there...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Page Routing&lt;/strong&gt;
I then went ahead to route my pages using ReactRouter and i aslo created a 404 page for extra functionality.
&lt;/li&gt;
&lt;/ul&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;Home /&amp;gt;} /&amp;gt;
          &amp;lt;Route path="/RepositorySearch" element={&amp;lt;RepositorySearch /&amp;gt;} /&amp;gt;

          &amp;lt;Route path="*" element={&amp;lt;NotFound /&amp;gt;} /&amp;gt;
        &amp;lt;/Routes&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Styled up my page using CSS&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Setting Up Pagination.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pagination is a process that is used to divide large data into smaller discrete pages. Where a user can use links such as "next", "previous", and page numbers to navigate between pages, it enables a dynamic display of one page of results at a time.&lt;/p&gt;

&lt;p&gt;Firstly, I started by creating the variable postPerPage, which specified the number of items that will be displayed on each page.&lt;br&gt;
Then I created a state variable called pageNumbers  which i set to totalPosts / postPerPage&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Pagination = ({ postsPerPage, totalPosts }) =&amp;gt; {
  const pageNumbers = [];

  for (let i = 1; i &amp;lt;= Math.ceil(totalPosts / postsPerPage); i++) {
    pageNumbers.push(i);
  }
  return (
    &amp;lt;nav&amp;gt;
      &amp;lt;ul&amp;gt;
        {pageNumbers.map((number) =&amp;gt; (
          &amp;lt;li key={number}&amp;gt;
            &amp;lt;a href="!#"&amp;gt;{number}&amp;lt;/a&amp;gt;
          &amp;lt;/li&amp;gt;
        ))}
      &amp;lt;/ul&amp;gt;
    &amp;lt;/nav&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;The state property pageNumbers determines the page that will be displayed. As it changes the displayed page changes too.&lt;/p&gt;

&lt;p&gt;Next, I needed buttons...&lt;/p&gt;

&lt;p&gt;So i created a Next and Previous buttons in my Resuslt.js file to paginate through the lists of Repos being displayed&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;div className="buttons"&amp;gt;
        &amp;lt;button onClick={() =&amp;gt; getRepos(1)} className="previous"&amp;gt;
          Previous
        &amp;lt;/button&amp;gt;
        &amp;lt;button onClick={() =&amp;gt; getRepos(2)} className="next"&amp;gt;
          Next
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then i styled it all using CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  CONCLUSION
&lt;/h2&gt;

&lt;p&gt;This article is to just point out the process in which every implementation were made. Once agin, i was able to create my RepoSearch App with the help of React-Router, React-Error-Boundary, and GitHub API(for the API fetch) and all my styles were written in CSS(Cascading style sheet). &lt;/p&gt;

&lt;p&gt;Here is the link to the source code &lt;a href="https://github.com/iiphe/SearchRepos"&gt;https://github.com/iiphe/SearchRepos&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And a link to the live code&lt;br&gt;
&lt;a href="https://search-reposapp.vercel.app/repositorySearch"&gt;https://search-reposapp.vercel.app/repositorySearch&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for Reading&lt;/p&gt;

</description>
      <category>hashnode</category>
      <category>react</category>
      <category>webdev</category>
      <category>github</category>
    </item>
  </channel>
</rss>
