HomeSoftware EngineeringEmbed your GitHub challenge in your React web site | by Sabesan...

Embed your GitHub challenge in your React web site | by Sabesan Sathananthan


Embed GitHub repo in your Web site utilizing Materials-UI provides higher UI

Photograph by Markus Winkler on Unsplash

They are saying imitation is a type of flattery however honey, it’s time to get your individual concepts.

I assumed to embed my GitHub tasks on my web site like pinned repositories in GitHub. First I confronted an issue that how may I get the programming language colours as proven in GitHub. Then I discovered that was outlined in GitHub linguist. However linguist file outlined in YAML Due to this fact, I fetched that knowledge and convert it to JSON. Due to this fact I created an API to fetch the linguist particulars. However On this article, I’m not going to speak about that. If you wish to watch the API repository click on the hyperlink. Right here I’ll describe how I created the GitHub repository playing cards in React software. That is my thirty third Medium article.

On this article, I’m going to say how you can begin from scratch. Right here you can see the stay demo of this react software. Now I completed this challenge and have a repo in GitHub.

First, it is advisable to create a react software. For that run the next command in your shell/terminal in a particular folder (e.g., desktop )

npx create-react-app github-repo

A brand new folder shall be created, and it is going to be named as a github-repo. From this step, our software is bootstrapped with Create React App. For extra info, click on the hyperlink. Then open that challenge in your IDE. I’m personally utilizing the VS Code IDE. You could delete some recordsdata and set up the recordsdata for the event after you open the folder in your IDE. Due to this fact it is advisable to go to the src folder and delete Brand.svg, App.css, index.css, and App.check.js recordsdata. And create the next folders contained in the src folder named parts and api.

Now open the index.js file and delete the next snippet in index.js file.

import ‘./index.css’;
Photograph by Dhaya Eddine Bentaleb from Pexels

Set up Materials-UI for Materials Design type part.

npm set up @material-ui/core --save

Set up Axios to make HTTP requests to the API.

npm set up axios --save

Notice: Fetching JSON Knowledge could be achieved by the fetch API in JavaScript. Purpose for utilizing Axios Even outdated browsers like IE11 can run Axios with none subject. Fetch(), then again, solely helps Chrome 42+, Firefox 39+, Edge 14+, and Safari 10.1+ (you possibly can see the total compatibly desk on Can I exploit…)

Open the index.html file within the public folder and paste the beneath code contained in the <head> </head> tag.

<hyperlink rel=”stylesheet” href=”" />

the above course of shouldn’t be putting in the bundle. You’re going to use octionsCDN.

Photograph by cottonbro from Pexels

Very first thing first it is advisable to go to GitHub after which go to the settings. Click on the Developer Settings within the left column. Click on the non-public entry token and generate a brand new token and duplicate that token. open your react challenge and create a brand new file within the root folder named .env. Contained in the .env file add the next code. Exchange your copied GitHub Private Entry Token as an alternative of Your_Personal_Access_Token .

REACT_APP_API_KEY = Your_Personal_Access_Token

Contained in the api folder create a brand new file named Github.js. Add the next code within the Github.js file.

Exchange your GitHub consumer title as an alternative of sabesansathananthan on line 2.

Contained in the parts folder, create a brand new file named GitHubCards.js. Add the next code within the GitHubCards.js file.

In line 28, You might be fetching the linguist API utilizing Axios and you then set your language state. Kind line 31 to line 42, You might be fetching GitHub API for every repository. From line 46 to 52, You might be sorting repo array components based on the stargazers_count (stars rely).

Contained in the parts folder, create a brand new file named RepoCard.js. Add the next code within the RepoCard.js file.

The above useful part returns JSX components and Materials-UI parts.

Lastly, Render the GitHubCards part in App.js, as proven beneath.


Right here I’ve showcased 4 steps to embed GitHub repositories in your React web site. There are lots of react tasks for embed GitHub repositories in your React web site. However how that is totally different from different challenge playing cards is these playing cards present the colour dots associated to a programming language based on GitHub linguist. You may clone the Repo from this hyperlink. If you will use this challenge then Don’t overlook to present a star⭐️ for this repo.

Joyful Coding 😊 !!!



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments