<?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: Ajoke-Amupitan</title>
    <description>The latest articles on DEV Community by Ajoke-Amupitan (@ajokeamupitan).</description>
    <link>https://dev.to/ajokeamupitan</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%2F1005952%2Fec3c0268-652d-455a-87de-b2953d535f9c.png</url>
      <title>DEV Community: Ajoke-Amupitan</title>
      <link>https://dev.to/ajokeamupitan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ajokeamupitan"/>
    <language>en</language>
    <item>
      <title>Creating a portfolio App in React using the Github REST API</title>
      <dc:creator>Ajoke-Amupitan</dc:creator>
      <pubDate>Wed, 11 Jan 2023 12:29:05 +0000</pubDate>
      <link>https://dev.to/ajokeamupitan/creating-a-portfolio-app-in-react-using-the-github-rest-api-271b</link>
      <guid>https://dev.to/ajokeamupitan/creating-a-portfolio-app-in-react-using-the-github-rest-api-271b</guid>
      <description>&lt;p&gt;In this article, we will learn how to create a react application that interacts with the Github REST API. Some of the libraries we will be using are &lt;code&gt;react-icons&lt;/code&gt;, &lt;code&gt;react-router-dom&lt;/code&gt;, &lt;code&gt;react-helmet&lt;/code&gt; and &lt;code&gt;Error-Boundary&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This project was created using create-react-app.&lt;br&gt;
Before anything else, let's see how to install Create React App. The following command will create a new react project for us:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-react-app github-portfolio-app&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will start the installation process for Create React App, which can take several minutes, depending on your hardware. Although we're only executing one command, the installer for Create React App will install the packages we need to run our React application. Therefore, it will install &lt;code&gt;react&lt;/code&gt;, &lt;code&gt;react-dom&lt;/code&gt;, and &lt;code&gt;react-scripts&lt;/code&gt;, where the last package includes all the configurations for compiling, running, and building React applications.&lt;/p&gt;

&lt;p&gt;To be able to open the project in the browser, we can simply type the following command into the command line, which runs package react-scripts in development mode:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating reusable components&lt;/strong&gt;&lt;br&gt;
React makes it possible for us to create custom components that we can reuse throughout the project.&lt;br&gt;
First, lets create a &lt;code&gt;NavBar.js&lt;/code&gt; component;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { FaGithub } from "react-icons/fa"

function NavBar() {
    return (
        &amp;lt;div className="nav__bar"&amp;gt;
            &amp;lt;FaGithub className="github-icon"/&amp;gt;
            &amp;lt;h1&amp;gt;My GitHub Portfolio.&amp;lt;/h1&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Implementing API fetch&lt;/strong&gt;&lt;br&gt;
We need to create another component where we will implement the API fetch of our Portfolio. Lets call this component &lt;code&gt;Home.js&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;import React from 'react'

const Home = () =&amp;gt; {
return (
&amp;lt;div&amp;gt;
&amp;lt;/div&amp;gt;
)
};

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

&lt;/div&gt;



&lt;p&gt;We will go ahead and import &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt; into the &lt;code&gt;Home.js&lt;/code&gt;. The &lt;code&gt;useState&lt;/code&gt; hook will be used for storing variables that are part of our application's state and will change as the user interacts with our website. The &lt;code&gt;useEffect&lt;/code&gt; hook allows components to react to lifecycle events such as mounting to the DOM, re-rendering, and unmounting.&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, { useState, useEffect} from 'react'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will create a function named &lt;code&gt;fetchRepos&lt;/code&gt; in the &lt;code&gt;Home.js&lt;/code&gt; that will get data from our GitHub repos API and then save it in a state named &lt;code&gt;user&lt;/code&gt;. Then we create another function named &lt;code&gt;userInfos&lt;/code&gt;. This function will return our mapped data that we got from the github API response.&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, { useEffect, useState } from "react"

function Home() { 

  const [user, setUser] = useState([])

  const fetchRepos = () =&amp;gt; {
    fetch(`https://api.github.com/users/Ajoke-Amupitan/repos`)
    .then((response) =&amp;gt; (response.json()))
    .then((data) =&amp;gt; {
        setUser(data)  
    })
  }

  useEffect(() =&amp;gt; {
    fetchRepos()
  }, []) 

  const userInfos = user.map((userInfo) =&amp;gt; {
        return (
            &amp;lt;div className="repo-card" key={userInfo.id}&amp;gt;
                &amp;lt;h2 className="repo-name"&amp;gt;{userInfo.name}&amp;lt;/h2&amp;gt;
                &amp;lt;p className="language"&amp;gt;Langauge{userInfo.language === null ? "none" : userInfo.language}&amp;lt;/p&amp;gt;
                &amp;lt;p className="date"&amp;gt;Start date &amp;amp; time: {userInfo.created_at}&amp;lt;/p&amp;gt;
                &amp;lt;p className="visibility"&amp;gt;Visibility: {userInfo.visibility}&amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
        )
  })

  return (
      &amp;lt;&amp;gt;
        &amp;lt;section className="repo-container"&amp;gt;
            {userInfos}
        &amp;lt;/section&amp;gt;
      &amp;lt;/&amp;gt;
  )
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this article, we've been able to create a react application that gets some data from the github API and displays the data for the user to see on the User Interface. We also implemented several features and third part libraries.&lt;/p&gt;

&lt;p&gt;Tnanks for taking the time to read through this article and I hope you loved it.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>laravel</category>
      <category>softwaredevelopment</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
