Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

React
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
  • How a Web Page Works: HTML Tags, Elements and Attributes
  • Semantic HTML: header, nav, main, aside and footer as Page Landmarks
  • HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
  • CSS Basics: Selectors, Which Rule Wins, and the Box Model
  • CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
  • Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
  • JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
  • JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
  • Async JavaScript: Promises, async/await, fetch and Promise.all
  • JavaScript in the Page: the DOM, querySelector and Events
  • npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
  • TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
  • Why React, JSX and Components: The Page as a Function of Data
  • React Props and Composition: Data Down, Calls Up, Children in the Slot
  • Routing With React Router: One Page, Many Addresses
  • React Component Tests With Vitest and Testing Library: Test What the User Sees
  • End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
  • Why AI-Built Websites All Look the Same, and Four Levels That Fix It
  • Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
  • Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
  • Typography That Sells: Type Scale, Line Length and Free Font Pairings
  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
  • Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
  • shadcn/ui in React: Components You Own, Edit and Commit
  • Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
  • Motion in React: Entrance, Hover, Exit and Layout Animations
  • A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
  • Accessibility in Practice: Dialogs, Menus and the Keyboard in React
  • Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
  • Components, Variants and Variables: One Design System in Figma and in CSS
  • Figma MCP Server: Build a React Component From a Frame, Then Write It Back
  • Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
  • Critiquing AI-Generated UI: Six Checks for Every Screen
  • The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
  • Your Brand Rules Folder: One Folder Every AI-Built Page Follows
  • The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
  • UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
  • Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
  • Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
  • Figma Make: Prompt to Prototype With a Four-Part Prompt
  • Upgrade a Dated UI From One Screenshot (or a Reference Image)
  • States and Feedback: Make Every Click Get an Answer
  • A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
  • Copy Without the AI Tells: A Copy Pass on a Landing Page
  • React State, Events, Lists and Conditional Rendering: Follow One Click
  • React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
  • Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
  • Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
  • React Context and Custom Hooks: Share One Value, Reuse the Logic
  • Server State With TanStack Query: One Key, One Request, One Cache
  • Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
  • Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
  • A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
  • JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
  1. Blog
  2. /
  3. React
  4. /
  5. Fundamentals

A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table

Build a small sales dashboard in React: four stat cards, a Recharts line chart that disappears when its parent has no height, and an orders table that sorts with one boolean in state, all in a Tailwind grid.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Fundamentals

What you will learn

  • Build a stat card component with label, value and change props
  • Draw a responsive line chart with Recharts and give its parent a real height
  • Sort a table with one piece of state without changing the original array
  • Lay out a dashboard with a responsive Tailwind grid

Before you start

  • Tailwind CSS 4 in React
  • React useState

Think about a car dashboard and what the driver really needs. The speedometer: one number, how fast right now, read in a glance. The trip graph: where things are heading, a trend. The trip log: the exact details of what happened.

A good web dashboard works the same way. One number, a trend, and the details. Show those three, and everything else is clutter. In this article you build a small sales dashboard from three pieces: a stat card, a line chart and a sortable table.

Sales overview dashboard: four stat cards (Revenue $35.8k +12% this month, Orders 482 +8%, Customers 1,240 +5%, Avg. order $74 +3%), a Revenue by month line chart rising from Jan to Jun, and a Recent orders table sorted by total from Priya $240 down to Lucas $60.
The finished dashboard: one number per card, a trend and the details.

The data

All three pieces read from one sample file, data.ts:

export type Order = { id: number; customer: string; status: 'Paid' | 'Pending'; total: number }

export const monthly = [
  { month: 'Jan', revenue: 4200 },
  { month: 'Feb', revenue: 5100 },
  { month: 'Mar', revenue: 4800 },
  { month: 'Apr', revenue: 6200 },
  { month: 'May', revenue: 7400 },
  { month: 'Jun', revenue: 8100 },
]

export const orders: Order[] = [
  { id: 1, customer: 'Emma', status: 'Paid', total: 120 },
  { id: 2, customer: 'Jack', status: 'Pending', total: 85 },
  { id: 3, customer: 'Priya', status: 'Paid', total: 240 },
  { id: 4, customer: 'Lucas', status: 'Paid', total: 60 },
  { id: 5, customer: 'Sofia', status: 'Pending', total: 175 },
]

export const stats = [
  { label: 'Revenue', value: '$35.8k', change: '+12% this month' },
  { label: 'Orders', value: '482', change: '+8% this month' },
  { label: 'Customers', value: '1,240', change: '+5% this month' },
  { label: 'Avg. order', value: '$74', change: '+3% this month' },
]

Stat card: one glance

type Props = { label: string; value: string; change: string }

export default function StatCard({ label, value, change }: Props) {
  return (
    <div className="rounded-xl bg-white p-5 shadow">
      <p className="text-sm text-slate-500">{label}</p>
      <p className="mt-1 text-3xl font-bold">{value}</p>
      <p className="mt-1 text-sm text-emerald-600">{change}</p>
    </div>
  )
}

The card takes three props, typed on the first line: label, value and change. The label is small grey text (text-sm text-slate-500) that says what the number is. The value is big and bold (text-3xl font-bold), and the eye lands there first. The change is small and green (text-emerald-600), so you see the direction. One card, one number.

Line chart with Recharts

For the chart we use Recharts, a popular chart library for React:

import {
  Line,
  LineChart,
  ResponsiveContainer,
  Tooltip,
  XAxis,
  YAxis,
} from 'recharts'
import { monthly } from './data'

export default function RevenueChart() {
  return (
    <div className="h-56">
      <ResponsiveContainer width="100%" height="100%">
        <LineChart data={monthly}>
          <XAxis dataKey="month" />
          <YAxis />
          <Tooltip />
          <Line dataKey="revenue" stroke="#2563eb" strokeWidth={3} />
        </LineChart>
      </ResponsiveContainer>
    </div>
  )
}

The first thing inside is a div with h-56. That is the parent, with a fixed height. Inside it sits ResponsiveContainer at 100% width and height, so the chart fills that parent, wide or narrow. LineChart gets the monthly array. XAxis reads the month key, YAxis works out the numbers by itself, and Tooltip gives you a popup on hover for free. Finally Line draws the revenue key in blue with a thick stroke.

From data to drawing

How Recharts turns data into a drawing 1. Data{ month: 'Jan',revenue: 4200 } 2. LineChartdata={monthly} 3. PartsXAxis: monthLine: revenue 4. Screenan SVG thatfits the box You describe the data. The library does the drawing.
Each chart part reads one key from every object in the array.

You do not need to memorise every chart option, because AI can generate those. But you need this foundation so the code makes sense when you read it.

Break it: no height, no chart

This is a very common mistake. Remove the height from the parent:

// before
<div className="h-56">
// after
<div>
The Revenue by month card with only its heading. No chart is drawn.
Without h-56: the title, and nothing else.

ResponsiveContainer says 100%. But 100% of what? The parent has no height, so the chart is zero pixels tall. All you see is the title. No error message, just an empty card. Put h-56 back and the chart is there again.

The rule: a chart that fills 100% needs a parent with a real height.

Table: sort with state

import { useState } from 'react'
import { orders } from './data'

export default function OrdersTable() {
  const [desc, setDesc] = useState(true)
  const sorted = [...orders].sort((a, b) => a.total - b.total)
  const rows = desc ? sorted.reverse() : sorted
  const toggle = () => setDesc(!desc)

  return (
    <table className="w-full text-left">
      <thead className="text-sm text-slate-500">
        <tr>
          <th>Customer</th>
          <th>Status</th>
          <th onClick={toggle}>Total {desc ? 'â–¼' : 'â–²'}</th>
        </tr>
      </thead>
      <tbody>
        {rows.map((o) => (
          <tr key={o.id} className="border-t border-slate-100">
            <td className="py-2">{o.customer}</td>
            <td>{o.status}</td>
            <td>${o.total}</td>
          </tr>
        ))}
      </tbody>
    </table>
  )
}

Which way we sort is one piece of state, desc. It starts as true, so the highest total comes first.

[...orders] makes a copy, and the copy is sorted by total. Never sort the original array: sort changes the array in place, and that would change the data underneath. If desc is true, the copy is reversed.

The Total header is clickable. A click calls toggle, which flips desc, and React redraws the rows in the new order with the arrow turned around. Each row gets key={o.id} so React can tell the rows apart.

The Recent orders table twice. Left, Total with a down arrow: Priya $240, Sofia $175, Emma $120, Jack $85, Lucas $60. Right, after a click, Total with an up arrow: Lucas $60, Jack $85, Emma $120, Sofia $175, Priya $240.
Left: the default, highest first. Right: after one click on Total.

Put it together: a grid

import OrdersTable from './OrdersTable'
import RevenueChart from './RevenueChart'
import StatCard from './StatCard'
import { stats } from './data'

export default function App() {
  return (
    <main className="mx-auto max-w-5xl space-y-6 p-6">
      <h1 className="text-2xl font-bold">Sales overview</h1>
      <section className="grid grid-cols-2 gap-4 md:grid-cols-4">
        {stats.map((s) => (
          <StatCard key={s.label} {...s} />
        ))}
      </section>
      <section className="grid gap-4 md:grid-cols-5">
        <div className="rounded-xl bg-white p-5 shadow md:col-span-3">
          <h2 className="mb-3 font-semibold">Revenue by month</h2>
          <RevenueChart />
        </div>
        <div className="rounded-xl bg-white p-5 shadow md:col-span-2">
          <h2 className="mb-3 font-semibold">Recent orders</h2>
          <OrdersTable />
        </div>
      </section>
    </main>
  )
}

The first row is a grid: two columns on a phone, four from the md breakpoint. The four stat cards come from one array with map, so a fifth card is just one more object in stats. The second row is a five-column grid: the chart takes three columns (md:col-span-3) and the table takes two. Each sits in a white card with a heading. Resize the window and it adapts.

Which block, and when?

You want to showUse
One number that mattersStat card
How something changes over timeLine chart
A comparison of a few groupsBar chart (same Recharts, bars instead of a line)
Exact values to scan and sortTable

Every block on a dashboard must earn its place. If nobody reads it, remove it.

Common mistakes

  • A chart parent with no height. No error, no chart.
  • Sorting the original array. orders.sort(...) mutates the shared data. Copy first with [...orders].
  • Using the index as the row key. After a sort, the index no longer points at the same order. Use the id.
  • Too many blocks. One number, a trend, the details. The rest is clutter.

Recap

A stat card for one number, a chart for a trend, a table for the details, and a grid to hold them. We covered the foundations, and with AI you can generate the rest. Try it yourself: add a bar chart of orders per status to the second row and give it a col-span that fits.

Keep going in React · 30 of 59

Previous
Motion in React: Entrance, Hover, Exit and Layout Animations
Next post
Accessibility in Practice: Dialogs, Menus and the Keyboard in React
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

One Request, Two Answers: the Same Post as an HTML Page and as JSON

Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.

A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx

Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.

How a Web Page Works: HTML Tags, Elements and Attributes

A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.

Semantic HTML: header, nav, main, aside and footer as Page Landmarks

The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.

On this page

  • The data
  • Stat card: one glance
  • Line chart with Recharts
  • From data to drawing
  • Break it: no height, no chart
  • Table: sort with state
  • Put it together: a grid
  • Which block, and when?
  • Common mistakes
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.