Skip to main content

Beginner-Friendly Topic

Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!

Lesson 9 of 10

Mini Project: Interactive Profile Card

Build a fully interactive Profile Card component that brings together everything from Module 1: component architecture, TypeScript props, useState, event handling, conditional rendering, and list rendering. This project mirrors real components you'd build in a professional React application.

45 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Project: Interactive Profile Card with Stats & Follow System

Project: Interactive Profile Card with Stats & Follow System
import { useState } from 'react';

// Types - always define data shapes first
interface Skill {
  name: string;
  level: 'beginner' | 'intermediate' | 'advanced' | 'expert';
}

interface UserProfile {
  id: string;
  name: string;
  role: string;
  bio: string;
  avatarUrl: string;
  location: string;
  skills: Skill[];
  stats: {
    followers: number;
    following: number;
    projects: number;
  };
  isVerified: boolean;
}

// Skill level color mapping - outside component to avoid recreation on renders
const levelColors: Record<Skill['level'], string> = {
  beginner: '#6ee7b7',
  intermediate: '#60a5fa',
  advanced: '#2eb87f',
  expert: '#f59e0b',
};

// SkillBadge - small, focused, reusable
function SkillBadge({ skill }: { skill: Skill }) {
  return (
    <span
      style={{
        background: levelColors[skill.level],
        padding: '2px 10px',
        borderRadius: '999px',
        fontSize: '12px',
        color: '#1a1a2e',
        fontWeight: 600,
      }}
    >
      {skill.name}
    </span>
  );
}

// StatItem - displays a single stat
function StatItem({ label, value }: { label: string; value: number }) {
  return (
    <div style={{ textAlign: 'center' }}>
      <div style={{ fontSize: '20px', fontWeight: 700 }}>
        {value >= 1000 ? `${(value / 1000).toFixed(1)}k` : value}
      </div>
      <div style={{ fontSize: '12px', color: '#9ca3af' }}>{label}</div>
    </div>
  );
}

// ProfileCard - main component
interface ProfileCardProps {
  profile: UserProfile;
  onMessage?: (userId: string) => void;
}

function ProfileCard({ profile, onMessage }: ProfileCardProps) {
  const [isFollowing, setIsFollowing] = useState(false);
  const [followerCount, setFollowerCount] = useState(profile.stats.followers);
  const [activeTab, setActiveTab] = useState<'skills' | 'stats'>('skills');

  function handleFollow() {
    setIsFollowing(prev => {
      const next = !prev;
      setFollowerCount(c => next ? c + 1 : c - 1);
      return next;
    });
  }

  return (
    <div style={{
      width: 320, borderRadius: 16, overflow: 'hidden',
      boxShadow: '0 8px 32px rgba(0,0,0,0.3)',
      fontFamily: 'system-ui, sans-serif',
      background: '#1e293b', color: 'white',
    }}>
      {/* Header Banner */}
      <div style={{ height: 80, background: 'linear-gradient(135deg, #667eea, #764ba2)' }} />

      {/* Avatar */}
      <div style={{ padding: '0 20px', marginTop: -40 }}>
        <div style={{ position: 'relative', display: 'inline-block' }}>
          <img
            src={profile.avatarUrl}
            alt={profile.name}
            style={{ width: 72, height: 72, borderRadius: '50%', border: '3px solid #1e293b', objectFit: 'cover' }}
          />
          {profile.isVerified && (
            <span style={{
              position: 'absolute', bottom: 2, right: 2,
              background: '#229c6b', borderRadius: '50%',
              width: 18, height: 18, display: 'flex', alignItems: 'center',
              justifyContent: 'center', fontSize: 10,
            }}>
              โœ“
            </span>
          )}
        </div>
      </div>

      {/* Profile Info */}
      <div style={{ padding: '8px 20px 0' }}>
        <h2 style={{ margin: 0, fontSize: 18 }}>{profile.name}</h2>
        <p style={{ margin: '2px 0', color: '#93c5fd', fontSize: 13 }}>{profile.role}</p>
        <p style={{ margin: '4px 0 0', fontSize: 13, color: '#9ca3af' }}>๐Ÿ“ {profile.location}</p>
        <p style={{ fontSize: 13, color: '#d1d5db', marginTop: 8 }}>{profile.bio}</p>
      </div>

      {/* Actions */}
      <div style={{ display: 'flex', gap: 8, padding: '12px 20px' }}>
        <button
          onClick={handleFollow}
          style={{
            flex: 1, padding: '8px',
            background: isFollowing ? 'transparent' : '#229c6b',
            color: isFollowing ? '#9ca3af' : 'white',
            border: isFollowing ? '1px solid #4b5563' : 'none',
            borderRadius: 8, cursor: 'pointer', fontWeight: 600, fontSize: 13,
          }}
        >
          {isFollowing ? 'โœ“ Following' : '+ Follow'}
        </button>
        {onMessage && (
          <button
            onClick={() => onMessage(profile.id)}
            style={{
              flex: 1, padding: '8px', background: 'transparent',
              color: '#9ca3af', border: '1px solid #4b5563',
              borderRadius: 8, cursor: 'pointer', fontSize: 13,
            }}
          >
            ๐Ÿ’ฌ Message
          </button>
        )}
      </div>

      {/* Tabs */}
      <div style={{ display: 'flex', borderBottom: '1px solid #374151' }}>
        {(['skills', 'stats'] as const).map(tab => (
          <button
            key={tab}
            onClick={() => setActiveTab(tab)}
            style={{
              flex: 1, padding: '10px', background: 'none', border: 'none',
              color: activeTab === tab ? '#60a5fa' : '#6b7280',
              borderBottom: activeTab === tab ? '2px solid #60a5fa' : '2px solid transparent',
              cursor: 'pointer', fontWeight: activeTab === tab ? 600 : 400,
              fontSize: 13, textTransform: 'capitalize',
            }}
          >
            {tab}
          </button>
        ))}
      </div>

      {/* Tab Content */}
      <div style={{ padding: '16px 20px 20px' }}>
        {activeTab === 'skills' && (
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
            {profile.skills.map(skill => (
              <SkillBadge key={skill.name} skill={skill} />
            ))}
          </div>
        )}
        {activeTab === 'stats' && (
          <div style={{ display: 'flex', justifyContent: 'space-around' }}>
            <StatItem label="Followers" value={followerCount} />
            <StatItem label="Following" value={profile.stats.following} />
            <StatItem label="Projects" value={profile.stats.projects} />
          </div>
        )}
      </div>
    </div>
  );
}

// Usage in App.tsx
const sampleProfile: UserProfile = {
  id: 'u1',
  name: 'Priya Sharma',
  role: 'Senior React Engineer',
  bio: 'Building scalable UIs with React, TypeScript, and a lot of coffee. โ˜•',
  avatarUrl: 'https://i.pravatar.cc/150?img=47',
  location: 'Bangalore, India',
  isVerified: true,
  stats: { followers: 2400, following: 312, projects: 48 },
  skills: [
    { name: 'React', level: 'expert' },
    { name: 'TypeScript', level: 'advanced' },
    { name: 'Node.js', level: 'intermediate' },
    { name: 'GraphQL', level: 'intermediate' },
    { name: 'Docker', level: 'beginner' },
  ],
};

export default function App() {
  return (
    <div style={{ minHeight: '100vh', display: 'flex', alignItems: 'center', justifyContent: 'center', background: '#0f172a' }}>
      <ProfileCard
        profile={sampleProfile}
        onMessage={id => alert(`Message to user ${id}`)}
      />
    </div>
  );
}

What This Project Demonstrates

  • Component decomposition - `ProfileCard` composed of `SkillBadge` and `StatItem` focused sub-components
  • TypeScript interfaces - `UserProfile`, `Skill`, `ProfileCardProps` with optional callbacks
  • useState with functional updater - `handleFollow` uses `setIsFollowing(prev => !prev)` and `setFollowerCount(c => ...)` to avoid stale state
  • Conditional rendering - verified badge (&&), tabs content (separate ternary branches), follow button text/style
  • Dynamic styling - inline styles driven by state and data (level colors, active tab indicator, follow button appearance)
  • List rendering with keys - skills mapped with `key={skill.name}`, tabs mapped with `key={tab}`
  • Constants outside component - `levelColors` defined once outside the function, not recreated on every render
  • Optional callback prop - `onMessage` is optional (`?`) and only renders the Message button when provided

Tip

Tip

Practice Mini Project Interactive Profile Card in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagramโ€ฆ

Visual architecture and flow for Mini Project: Interactive Profile Card

Practice Task

Note

Practice Task - (1) Write a working example of Mini Project Interactive Profile Card from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Mini Project Interactive Profile Card is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react code.

Key Takeaways

  • Build a fully interactive Profile Card component that brings together everything from Module 1: component architecture, TypeScript props, useState, event handling, conditional rendering, and list rendering.
  • Component decomposition - `ProfileCard` composed of `SkillBadge` and `StatItem` focused sub-components
  • TypeScript interfaces - `UserProfile`, `Skill`, `ProfileCardProps` with optional callbacks
  • useState with functional updater - `handleFollow` uses `setIsFollowing(prev => !prev)` and `setFollowerCount(c => ...)` to avoid stale state

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done