Aral Code

Effects & Data Lesson 13 of 13

React Final Project — Grade Tracker App

Build a complete React grade tracker with components, props, state, forms, validation, lists, filtering, sorting, editing, deleting and computed statistics.

Let's build a full app with everything from this course: a Grade Tracker where you add subjects and grades, see your average and DepEd descriptor, filter, sort and delete entries.

Plan the components

App                 (state: grades, filter, sort)
├── GradeForm       (own state: subject, grade; calls onAdd)
├── Stats           (shows average, highest, descriptor)
├── Toolbar         (filter + sort controls)
└── GradeList
    └── GradeRow    (one row; calls onDelete)

The list of grades is shared by Stats, Toolbar and GradeList, so it lives in App.

The app

Example Grade Tracker
<div id="root"></div>
<script src="/vendor/react.min.js"></script>
<script src="/vendor/react-dom.min.js"></script>
<script src="/vendor/babel.min.js"></script>
<style>
  body { font-family: system-ui, sans-serif; background: #f3f6f4; margin: 0; }
  .app { max-width: 520px; margin: 0 auto; padding: 14px; }
  .card { background: white; border-radius: 14px; padding: 14px; margin-bottom: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.06); }
  .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
  input, select, button { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid #ccd3cf; }
  button { background: #0f5c4d; color: white; border: 0; cursor: pointer; }
  button.ghost { background: transparent; color: #b4372b; }
  .stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
  .stats b { display: block; font-size: 22px; color: #0f5c4d; }
  .err { color: #b4372b; font-size: 14px; margin: 6px 0 0; }
  li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid #eee; }
  .fail { color: #b4372b; font-weight: bold; }
</style>
<script type="text/babel">
  const { useState } = React;

  function descriptor(g) {
    if (g >= 90) return "Outstanding";
    if (g >= 85) return "Very Satisfactory";
    if (g >= 80) return "Satisfactory";
    if (g >= 75) return "Fairly Satisfactory";
    return "Did Not Meet Expectations";
  }

  function GradeForm({ onAdd, existing }) {
    const [subject, setSubject] = useState("");
    const [grade, setGrade] = useState("");
    const [error, setError] = useState("");

    function submit(e) {
      e.preventDefault();
      const name = subject.trim();
      const g = Number(grade);
      if (!name) return setError("Enter a subject.");
      if (existing.some((x) => x.subject.toLowerCase() === name.toLowerCase())) return setError("That subject is already listed.");
      if (grade === "" || g < 60 || g > 100) return setError("Grade must be from 60 to 100.");
      onAdd({ id: Date.now(), subject: name, grade: g });
      setSubject(""); setGrade(""); setError("");
    }

    return (
      <form className="card" onSubmit={submit}>
        <div className="row">
          <input placeholder="Subject" value={subject} onChange={(e) => setSubject(e.target.value)} style={{ flex: 1 }} />
          <input type="number" placeholder="Grade" value={grade} onChange={(e) => setGrade(e.target.value)} style={{ width: 90 }} />
          <button>Add</button>
        </div>
        {error && <p className="err">{error}</p>}
      </form>
    );
  }

  function Stats({ grades }) {
    if (grades.length === 0) return <div className="card">Add your first grade to see your average. 📚</div>;
    const avg = grades.reduce((s, g) => s + g.grade, 0) / grades.length;
    const best = grades.reduce((a, b) => (b.grade > a.grade ? b : a));
    return (
      <div className="card">
        <div className="stats">
          <div><b>{avg.toFixed(2)}</b>Average</div>
          <div><b>{best.grade}</b>{best.subject}</div>
          <div><b>{grades.length}</b>Subjects</div>
        </div>
        <p style={{ textAlign: "center", marginBottom: 0 }}>{descriptor(avg)}{avg >= 90 && grades.every((g) => g.grade >= 85) ? " · With honors 🏅" : ""}</p>
      </div>
    );
  }

  function Toolbar({ filter, setFilter, sort, setSort }) {
    return (
      <div className="row" style={{ marginBottom: 8 }}>
        <select value={filter} onChange={(e) => setFilter(e.target.value)}>
          <option value="all">All subjects</option>
          <option value="failing">Below 75</option>
          <option value="high">90 and above</option>
        </select>
        <select value={sort} onChange={(e) => setSort(e.target.value)}>
          <option value="added">Order added</option>
          <option value="high">Highest first</option>
          <option value="az">A to Z</option>
        </select>
      </div>
    );
  }

  function GradeRow({ item, onDelete }) {
    return (
      <li>
        <span>{item.subject}</span>
        <span>
          <span className={item.grade < 75 ? "fail" : ""}>{item.grade}</span>
          <button className="ghost" onClick={() => onDelete(item.id)} aria-label={`Delete ${item.subject}`}>✕</button>
        </span>
      </li>
    );
  }

  function App() {
    const [grades, setGrades] = useState([
      { id: 1, subject: "Math", grade: 88 },
      { id: 2, subject: "Science", grade: 92 },
      { id: 3, subject: "English", grade: 85 },
    ]);
    const [filter, setFilter] = useState("all");
    const [sort, setSort] = useState("added");

    const shown = grades
      .filter((g) => filter === "all" || (filter === "failing" ? g.grade < 75 : g.grade >= 90))
      .slice()
      .sort((a, b) => sort === "high" ? b.grade - a.grade : sort === "az" ? a.subject.localeCompare(b.subject) : 0);

    return (
      <div className="app">
        <h2>📊 My Grade Tracker</h2>
        <GradeForm existing={grades} onAdd={(g) => setGrades([...grades, g])} />
        <Stats grades={grades} />
        <div className="card">
          <Toolbar filter={filter} setFilter={setFilter} sort={sort} setSort={setSort} />
          <ul style={{ listStyle: "none", padding: 0, margin: 0 }}>
            {shown.map((g) => (
              <GradeRow key={g.id} item={g} onDelete={(id) => setGrades(grades.filter((x) => x.id !== id))} />
            ))}
          </ul>
          {shown.length === 0 && <p>No subjects match this filter.</p>}
        </div>
      </div>
    );
  }

  ReactDOM.createRoot(document.getElementById("root")).render(<App />);
</script>

What each part teaches

PartConcepts
App stateLifting state up, array of objects
GradeFormControlled inputs, validation, callbacks, local state
StatsDerived values (average, best) computed during render, early return
ToolbarSelects controlled by parent state
shownFilter + sort without changing the original state
GradeRowProps, keys, delete with filter

Notice .slice() before .sort(): sort changes the array it's called on, and we must never change state directly, so we sort a copy.

Challenges

  1. Add an "Edit" button that lets you change a grade.
  2. Save grades to localStorage with useEffect (test it outside the Try-it editor).
  3. Track four quarters per subject and compute the final grade.
  4. Add a progress bar showing how close the average is to 90.
  5. Move it into a Vite project with one file per component, and deploy it.

What's next?

Congratulations on finishing the React course! 🎉 Good next steps: learn Next.js for full websites with routing, connect React to a real backend (see the PHP or SQL courses), or try React Native to build phone apps.

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. Why does the grades state live in App?
2. Why is the average not stored in state?
3. Why call .slice() before .sort()?
4. How is a grade deleted?

By Sir Reyel · Last updated 2026-12-04