ReactJS-The Beginner Master Class
  • React In the Beginning
    • Lesson 1 - Demo: Build a Simple React App - Fast
    • Lesson 2 - HTML Review
    • Lesson 3 - CSS Review
    • Lesson 4 - Modern JavaScript (JSX) Patterns
    • Lesson 5 - Set up Dev Environment
    • Hands-on Practice
  • React Fundamentals
    • Lesson 1 - Understanding Old vs New Way of Building Web Apps - SPAs
    • Lesson 2 - Motivation for Using React as the Solution to Vanilla JS
    • Lesson 3 - What is ReactJS - How it Works
    • React Code Along from Scratch
    • Lesson 4 - Create and Run a React Project with Vite - Full Overview
    • Lesson 5 - Create Hook by State Management in React
    • Lesson 6 - React Project File and Folder Walkthrough
    • Lesson 7 - JSX and How React Treats the DOM & JSX Compilation(by Babeljs) - Overview
    • Lesson 8 - Understanding the Main Files - App.jsx and main.jsx
    • Lesson 9 - Props and One-Way Data Flow - Overview
    • Lesson 10 - Google Bookshelf App - Ver 1.0
    • Hands-on Practice I
    • Hands-on Practice II
  • React State and Styling
    • Lesson 1 - Pulling Book Data from a Different Data File
    • Lesson 2 - Overview of How State Works in React
    • Lesson 3 - RandomQuote App
    • Lesson 4 - Lifting State Up - React Pattern Overview
    • Hands-On - Simple Counter
  • Forms and Interactivity - Grocery List App
    • Lesson 1 - Setup a Simple Form and Input
    • Lesson 2 - Build Form Profile App Using Multi-input Form Data
    • Hands-on : Build a Grocery List App
  • Connecting to the Backend - Consuming APIs - UseEffect Hook
    • Lesson 1 - Connecting to the Back End - Understanding Side Effects, Hooks and useEffect - Overview
    • Lesson 2 - Fetching Data from the Backend the Right Way with useEffect Hook
    • Lesson 3 - Setting Up Loading State
    • Hands-on :Use Dependency Array and Adding Values that Control Side Effects
  • Solo Project 1
  • RESTful APIs :Build a BookSearch App -Ver 2.0
    • Lesson 1: Build and test RESTful APIs with Postman
    • Lesson 2 - BookShelf App Structure
    • Lesson 3 - Create NavBar.jsx Component
    • Lesson 4 - Create Footer Component
    • Lesson 5 - Create BookList.jsx Component
    • Lesson 6 - Create BookCard.jsx Component
    • Lesson 7 - Creating Custom Hooks - useBooks and api-client
    • Lesson 8 - Controlling Network Activities in React with AbortController
    • Lesson 9 - Show Book Details in a Modal - Working
    • Lesson 10 - Bookshelf App Summary
  • Multi-Page Applications (MPAs)
    • Build a Multi-Page React Application
    • Multi-Page React Application
    • Hands-on Practice
  • Backend Frameworks-NEXT.JS
    • Migrating from React to Next.js
    • Lesson 1: Key Concepts of NodeJS and Express for Backend Web Development
    • Lesson 2: How to set up a new Next.js project
    • Lesson 3: How to create Layouts and Pages
    • Hands-on Practice 1
    • Hands on Practice 2
      • New Project & Folder Structure
      • File-Based Routing
      • Server vs Client Components & Router Hooks
      • Start On The Navbar
      • Navbar Links, Dropdowns & React Icons
      • Active Links & Conditional Rendering
      • Homepage Components
      • Properties Page
      • Property Card Dynamic Data
      • Home Property Listings
      • Custom Not Found & Loading Pages
  • Git and GitHubs
    • Git Installation
    • Git Commands
    • GitHub Repository
    • Hands-on Practice
  • Database in Application
    • React Supabase CRUD
    • Hands-on: Note Taking App
  • NoSQL Database
    • Installing MongoDB Community Edition
    • System Env Path Setting
    • How to use MongoDB Shell
    • How to Connect and Use Mongosh in VS Code via MongoDB Extension
    • MongoDB Guide
  • Solo Project 2
  • Deployment and Web Hosting
    • Lesson 1. React+Vite+TS+Shadcn Project
    • Lesson 2. Deploying a React Vite App to Vercel from Vercel CLI
    • Lesson 3 Connecting to GitHub Repo and Automate Deployment
  • Solo Project 3
  • Final Term Project
    • Level 1 Team Project
    • Level 1 Team Project
    • Level 1 Team Project
    • Level 1 Team Project
    • Level 2 Team Project
    • Level 2 Team Project
    • Level 3 Team Project
    • Level 3 Team Project
Powered by GitBook
On this page
  • UserProfile Card Challenge and Solution
  • A step-by-step guide to implementing a React User Profile App
  • Step 1. Setup the React App
  • Step 2. Create the Parent App.jsx Component
  • Step 3. Create the Child UserProfile.jsx Component
  • Step 4. Add Custom Styles (Optional)
  • Step 5. Test the Application
  1. React Fundamentals

Hands-on Practice I

PreviousLesson 10 - Google Bookshelf App - Ver 1.0NextHands-on Practice II

Last updated 2 months ago

UserProfile Card Challenge and Solution

Our Goal : User Profile App

A step-by-step guide to implementing a React User Profile App

Step 1. Setup the React App

  1. Open a terminal and create a new React app:

    npx create-react-app user-profile-app
    cd user-profile-app
  2. Install the Bootstrap package:

    npm install bootstrap
  3. Import Bootstrap into the index.js file:

    import 'bootstrap/dist/css/bootstrap.min.css';
    import './index.css'; // Optionally include your custom CSS

Step 2. Create the Parent App.jsx Component

// Layout Design for App.jsx
----------------------------------------
|                                      |<---- card container
|          User Profile App            |
|                                      |
|   -------------------------------    |<---- UserProfile container
|   |                             |    |
|   |       [ User Profile ]      |    |<----- UserProfile component
|   |                             |    |
|   -------------------------------    |
|                                      |
----------------------------------------
  1. Open src/App.jsx and set it up to include the child UserProfile component.

  2. Here is the updated App.jsx:

    
    import React from 'react'
    import UserCardProfile from './components/UserCardProfile'
    import './App.css'
    
    const UserCard = () => {
      const user = {
        userImage: 'src/assets/hnu-mypic.JPG', // Replace with a real image URL
        name: 'John Doe',
        email: 'johndoe@example.com',
        bio: 'Software developer with a passion for building great web applications.',
      }
    
      return (
        <>
          <h1 >User Profile App</h1>
          <div className="profile-container user-profile mt-5">
            <UserCardProfile {...user} />
          </div>
        </>
      )
    }
    
    export default UserCard
    

Step 3. Create the Child UserProfile.jsx Component

// Some code
------------------------------------------------------------
|                                                          |
|  ----------------------------------------------------    |<--- User Profile card container
|  | User Profile Card                                |    |
|  |--------------------------------------------------|    |<---- User Profile Layout
|  |  [ Profile Image ]    |  [ User Details Card ]   |    |      flex -row direction
|  |                       |                          |    |      Profile Image + User Details
|  |                       |  Name: [ John Doe ]      |    |
|  |                       |  Email: john@example.com |    |
|  |                       |  Bio: Software Developer |    |
|  ----------------------------------------------------    |
|                                                          |
------------------------------------------------------------
  1. Create a components folder in the src directory and add a file named UserProfile.jsx.

  2. Implement the UserProfile component:

    import React from 'react'
    import PropTypes from 'prop-types'
    
    const UserCardProfile = ({ userImage, name, email, bio }) => {
      console.log({userImage})
        return (
        <>
          {/* Left Item: User Image */}
          <div className="me-3">
            <img
              src={userImage}
              alt={`${name}'s profile`}
              className="img-fluid rounded-4"
              style={{ width: '250px', height: '200px', objectFit: 'cover' }}
            />
          </div>
    
          {/* Right Item: User Details */}
          <div >
            <h3 className="text-primary mb-2">{name}</h3>
            <p className="mb-1 text-muted">
              <strong>Email:</strong> {email}
            </p>
            <p className="mb-0 text-secondary">
              <strong>Bio:</strong> {bio}
            </p>
          </div>
        </>
      )
    }
    
    UserCardProfile.propTypes = {
      userImage: PropTypes.string.isRequired,
      name: PropTypes.string.isRequired,
      email: PropTypes.string.isRequired,
      bio: PropTypes.string.isRequired,
    }
    
    export default UserCardProfile
    

Step 4. Add Custom Styles (Optional)

  1. Create a src/App.css file to add custom styles :


// App.css
.card-container {
  display: flex;
  justify-content: center;
  /* Centers horizontally */
  align-items: center;
  /* Centers vertically */
  flex-direction: column;
  /* Optional: if you want the cards to stack vertically */
 /*  height: 100vh; */
  /* Optional: full viewport height */
  
}
.profile-container {
  max-width: 600px;
}

.user-profile {
  border: 1px solid #cc7979;
  border-radius: 15px;
  padding: 20px;
  max-width: 600px;
  margin: 20px auto;
  text-align: center;
}

Step 5. Test the Application

  1. Run the app:

    npm run dev
  2. Open the browser and navigate to http://localhost:5173. You should see the user profile displayed with the image on the left and name, email, and bio on the right.


6. Folder Structure Overview

After implementation, your folder structure should look like this:

user-profile-app/
├── src/
│   ├── components/
│   │   └── UserProfile.jsx
│   ├── index.css
│   ├── App.jsx
│   └── index.js
├── public/
├── package.json
└── node_modules/

This app now uses Bootstrap CSS for styling and follows the structure you described. You can customize further as needed!

UserProfile Card App