<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marianella Gomezluna on Medium]]></title>
        <description><![CDATA[Stories by Marianella Gomezluna on Medium]]></description>
        <link>https://medium.com/@marianella.gomezluna?source=rss-b7be65e4b45f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WOXqdU0_KSOinBtE</url>
            <title>Stories by Marianella Gomezluna on Medium</title>
            <link>https://medium.com/@marianella.gomezluna?source=rss-b7be65e4b45f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 03:50:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marianella.gomezluna/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to create a GIT Octokit integration in React and how to not die in process]]></title>
            <link>https://medium.com/@marianella.gomezluna/how-to-create-a-git-octokit-integration-in-react-and-how-to-not-die-in-process-97ca7fab3fc2?source=rss-b7be65e4b45f------2</link>
            <guid isPermaLink="false">https://medium.com/p/97ca7fab3fc2</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[octokit]]></category>
            <dc:creator><![CDATA[Marianella Gomezluna]]></dc:creator>
            <pubDate>Tue, 15 Aug 2023 21:54:20 GMT</pubDate>
            <atom:updated>2023-08-15T22:02:22.795Z</atom:updated>
            <content:encoded><![CDATA[<p>When I was creating my personal portfolio, I came to the realization that I wanted to showcase my Git repositories directly on it. This led me to explore how to integrate my Git repositories into my portfolio. As I pondered this, I recalled a past experience where I had taken on a challenge for a company (even though they ultimately didn’t hire me). The challenge had involved implementing a GitHub integration on the backend using Octokit. This memory sparked my curiosity and prompted me to figure out how to adapt this integration for my React frontend using a Custom Hook.</p><p>Why not, right? I initially thought the process would be straightforward, but as I delved into the integration aspects, I found myself grappling with various complexities. Despite the helpful documentation available, I encountered some roadblocks and needed to find a unique approach to make everything fit. It was challenging because there isn’t much documentation available for this process. Since it’s somewhat my brainchild, I’m determined to approach a solution that leads to a correct integration accessible for everyone.</p><p>But why Octokit?</p><p>Octokit is a set of client libraries and tools created by GitHub to interact with their RESTful API. It provides an easy way to programmatically access various GitHub features and data, such as repositories, issues, pull requests, user profiles, and more. Octokit simplifies the process of making API requests to GitHub and handling the responses.</p><p>Access to GitHub Data: Octokit allows you to fetch data from your GitHub repositories, user profiles, and other GitHub-related information. This can be useful for creating features like displaying repositories on a portfolio website, managing issues and pull requests, and more.</p><p>That’s why I embarked on a two-day journey to construct my portfolio, employing Typescript, Next.js, Tailwind, and React. As I reflect on the technologies I utilized, I realize that they were the driving factors that paved the way for a happy ending to my portfolio-building endeavor.</p><p>Enough of chit-chat, let’s roll up our sleeves!</p><p>For this, you’re going to need:</p><ul><li>A Next.js project or a React project; the only difference is the “use client” part. If you intend to use JavaScript, you can ignore the types. However, I suggest implementing TypeScript because it’s more accurate with types.</li><li>Set up your environment variables: use your personal data from Git. Obtain a public auth token by following these steps: Go to your GitHub account and navigate to “Developer settings,” then select “Personal access token.” Choose the “fine-grained token” option</li></ul><p>To initiate the integration, we should start by examining the documentation, particularly the documentation for octokit/rest.js: <a href="https://octokit.github.io/rest.js/v20">https://octokit.github.io/rest.js/v20</a></p><p>and of course you have to take a look at the endpoints at: <a href="https://docs.github.com/es/rest?apiVersion=2022-11-28">https://docs.github.com/es/rest?apiVersion=2022-11-28</a></p><p>This resource proves to be quite helpful, but our goal is to craft a Custom Hook for using Octokit.</p><p>Initially, you’ll want to set up the installation process. We’re going to need dotenv for environment variables and Octokit/rest for integration.</p><pre>npm install @octokit/rest<br>npm install dotenv</pre><p>Then, you want to make the magic start to happen!</p><p>Once you have your project ready, let’s focus on building our custom hook. In the first instance, it’s somewhat similar to creating a simple fetch API custom hook, but with some variations(don’t forget to import “use client” if you are in NextJs)</p><pre>&quot;use client&quot;<br>import { useEffect, useState } from &#39;react&#39;;<br>import { Octokit } from &#39;@octokit/rest&#39;;<br><br>const useOctokitFetch = (path) =&gt; {<br><br>    const [data, setData] = useState&lt;Array&lt;any&gt;&gt;();<br>    const [isLoading, setIsLoading] = useState&lt;Boolean&gt;(false);<br>    const [error, setError] = useState&lt;string&gt;();<br><br>    useEffect(() =&gt; {<br>            const fetchData = async () =&gt; {<br><br>                setIsLoading(true);<br><br>                try {<br>                   const response = await fetch(url);<br>                   const jsonData = await response.json();<br>                    setData(jsonData);<br>                } catch (err: any) {<br>                    setError(err.message || &#39;Error fetching data&#39;);<br>                }<br><br>                setIsLoading(false);<br>            };<br><br>            fetchData();<br>        }<br>    }, []);<br><br>    return { data, isLoading, error };<br>};<br><br>export default useOctokitFetch;</pre><p>For now, we’ll be making some adjustments to the example to make it suitable for our API integration:</p><p>First, we’ll add options to the parameters of the function:</p><pre>const useOctokitFetch = (path: string, options: UseOctokitFetchOptions) =&gt;{<br><br>}</pre><p>Of course, we’re going to define a UseOctokitFetchOptions type that will allow us to include our personal login data::</p><pre>type UseOctokitFetchOptions ={<br>username: string;<br>accesToken: string;<br>}</pre><p>Within our fetchData function, we&#39;ll create an instance of the Octokit object, and we&#39;ll declare the auth property, which will be accessed through the provided options.</p><pre>const octokit = new Octokit({<br>                    auth: options.accessToken, <br>                });</pre><p>Then, we’ll call the Octokit object, which offers several features. We’ll use the listForUser function and pass the username through our options:</p><pre>const response =  await octokit.rest.repos.listForUser({<br>username: options.username<br>})</pre><p>That’s it! But wait, you might encounter some errors where the code doesn’t load properly. That’s when we’ll apply the next step:</p><pre>    if (typeof window !== &#39;undefined&#39;) {<br>                const fetchData = async () =&gt; {<br>                    const octokit = new Octokit({<br>                        auth: options.accessToken,<br>                    });<br><br>                    setIsLoading(true);<br><br>                    try {<br>                        const response = await octokit.rest.repos.listForUser({<br>                            username: options.username,<br>                        });<br>                        setData(response.data);<br>                    } catch (err: any) {<br>                        setError(err.message || &#39;Error fetching data&#39;);<br>                    }<br><br>                    setIsLoading(false);<br>                };<br><br>                fetchData();<br>            }</pre><p>The line if (typeof window !== &#39;undefined&#39;) is used to check if the code is running in a browser environment (i.e., in a context where window is defined) before executing the code block within that conditional. This is commonly used in web applications to prevent certain code that relies on the browser from running when server-side rendering (SSR) is taking place, where the window object wouldn&#39;t be defined.</p><p>This could be useful because we’re in a server environment and we don&#39;t want the Octokit call to be made on the server, as window wouldn&#39;t be available. By wrapping the code in the if (typeof window !== &#39;undefined&#39;) conditional, we ensure that this code block only runs in a browser where window is defined. This can help prevent potential errors in server environments.</p><p>Last but not least, we’re going to create our .env file and pass the necessary information through the component from which you intend to make the API call.</p><pre>NEXT_PUBLIC_API_URL=https://api.github.com/users/username/details<br>NEXT_PUBLIC_API_URL_REPOS =https://api.github.com/users/username/repos<br>NEXT_PUBLIC_APP_AUTH=yourPublicKeyAuthGoesHere<br>NEXT_PUBLIC_USERNAME= yourUsername</pre><pre>const Repositories = () =&gt; {<br>    const username: string = process.env.NEXT_PUBLIC_USERNAME || &quot;&quot;<br>    const path: string = process.env.NEXT_PUBLIC_API_URL_REPOS || &quot;&quot;<br>    const accessToken: string = process.env.NEXT_PUBLIC_APP_AUTH || &quot;&quot;<br>    const { data, isLoading, error } = useOctokitFetch(path, { username, accessToken })<br>    const [hoveredRepoId, setHoveredRepoId] = useState(null);<br><br><br>    if (isLoading) {<br>        return &lt;&gt;&lt;div role=&quot;status&quot;&gt;<br>            &lt;svg aria-hidden=&quot;true&quot; viewBox=&quot;0 0 100 101&quot; fill=&quot;none&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;<br>                &lt;path d=&quot;M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z&quot; fill=&quot;currentColor&quot; /&gt;<br>                &lt;path d=&quot;M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z&quot; fill=&quot;currentFill&quot; /&gt;<br>            &lt;/svg&gt;<br>            &lt;span&gt;Loading...&lt;/span&gt;<br>        &lt;/div&gt;<br>        &lt;/&gt;<br>    }<br><br>    if (error) {<br>        return &lt;div&gt;&lt;h1&gt;En estos momentos estamos trabajando para mostrarte esta sección!&lt;/h1&gt;&lt;/div&gt;<br>    }<br><br><br>    return (<br>        &lt;&gt;<br>            &lt;div&gt;<br>                &lt;div&gt;<br>                    {data &amp;&amp; data.length &gt; 0 ? (<br>                        data.map((repo) =&gt; (<br>                            &lt;div<br>                                key={repo.id}<br>                                onMouseEnter={() =&gt; setHoveredRepoId(repo.id)}<br>                                onMouseLeave={() =&gt; setHoveredRepoId(null)}<br>                            &gt;<br>                                &lt;h2&gt;{repo.full_name}&lt;/h2&gt;<br>                                &lt;a href={repo.html_url}&gt;{repo.url}&lt;/a&gt;<br>                            &lt;/div&gt;<br>                        ))<br>                    ) : (<br>                        &lt;h1&gt;No se encontraron repositorios.&lt;/h1&gt;<br>                    )}<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/&gt;<br>    );<br>}</pre><p>And there you have it! You now have your Octokit integration set up to showcase your Git repositories on your own page.</p><p>You can see the full repository here: <a href="https://github.com/MarianellaGL/portfolio-mgl">https://github.com/MarianellaGL/portfolio-mgl</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97ca7fab3fc2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>