Mark L. Reyes

React Components: Bootstrap Card, Github API

I’m dabbling with React 18, displaying data in a separate component using hooks and fetch.


Introduction

Let’s build this. A simple React app which accesses Github’s REST API and prints a user’s profile into a Bootstrap 5 card interface.

What’s the Goal?

Create a separate component that displays a person’s Github profile.

What will we need?

Step By Step

Step 1: Create React App

From Stackblitz, click New project button and choose React JavaScript.

Step 2: Install Dependencies

From Stackblitz, open a new terminal and run: npm install react-bootstrap bootstrap

Step 3: Add Dependencies

From Stackblitz, add line 5 of main.jsx, import bootstrap.min.css.
From Stackblitz, add lines 5-8 of App.jsx, import React components Card, Container, Row, Col.

Step 4: Setup Hooks in Function, App()

From Stackblitz, App.jsx.

Step 5: Create Function, GitHubUser()

From Stackblitz, App.jsx, lines 10 through 33.
From Stackblitz, App.jsx, lines 59 through 66.

Key Takeaways

Outside of a successful call, data can be coming in many different states such as loading and error. This is due to the dependency of calling in a third party API. Extend this example by leveraging additional useState hooks, conditional rendering and catch method to display HTML which reflects those different use cases.

Additional Resources

Exit mobile version