MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Mini Project: Interactive Counter with Step Controls0%
Study Materials
React.js for BeginnersProgress 0%
1.1Why React and Single-Page Architecture1.2Setting Up Modern React with Vite1.3React Project Directory Structure and Entry Points1.4Virtual DOM and React Render Cycle Explained
10.1Mini Project: Interactive Counter with Step Controls10.2Mini Project: Dynamic FAQ Accordion10.3Mini Project: Real-Time Character Counter and Text Utility
HomeTutorialsReact.js for BeginnersMini Project: Interactive Counter with Step Controls
Mini Project: Dynamic FAQ Accordion

Mini Project: Interactive Counter with Step Controls

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. Project Overview & Requirements

In this hands-on mini-project, we will synthesize the foundational concepts of React—including useState, event handling, controlled inputs, and conditional rendering—into a full-featured, accessible Interactive Counter with Step Controls.

Requirements:

  1. 1
    Value Management: Maintain a current integer counter value.
  2. 2
    Step Increment / Decrement: Allow users to choose their step magnitude (e.g. step by 1, 5, 10, or custom).
  3. 3
    Boundaries & Limits: Enforce minimum (e.g. -50) and maximum (e.g. 100) boundaries with disabled button states.
  4. 4
    History Log: Keep a chronological log of previous actions (timestamp, action type, resulting value).
  5. 5
    Reset Capability: Reset the counter to 0 and clear history.
1┌────────────────────────────────────────────────────────┐
2│ Interactive Counter Utility │
3│ │
4│ [ 45 ] │
5│ │
6│ Step Size: [ 5 ] │
7│ [ - Decrement ] [ + Increment ] [ Reset ] │
8│ │
9│ Audit History: │
10│ • 14:02:10 - Incremented by 5 (New Value: 45) │
11│ • 14:02:08 - Incremented by 5 (New Value: 40) │
12└────────────────────────────────────────────────────────┘

2. Component Implementation

1import React, { useState } from 'react';
2 
3const MIN_VALUE = -50;
4const MAX_VALUE = 100;
5 
6export default function StepCounter() {
7 const [count, setCount] = useState(0);
8 const [step, setStep] = useState(1);
9 const [history, setHistory] = useState([]);
10 
11 // Helper to log actions
12 const logAction = (action, prevVal, nextVal) => {
13 const entry = {
14 id: Date.now(),
15 time: new Date().toLocaleTimeString(),
16 description: `${action} (from ${prevVal} to ${nextVal})`
17 };
18 setHistory((prev) => [entry, ...prev.slice(0, 9)]); // Keep last 10 entries
19 };
20 
21 // Handlers
22 const handleIncrement = () => {
23 setCount((prev) => {
24 const next = Math.min(prev + step, MAX_VALUE);
25 logAction(`Incremented by ${step}`, prev, next);
26 return next;
27 });
28 };
29 
30 const handleDecrement = () => {
31 setCount((prev) => {
32 const next = Math.max(prev - step, MIN_VALUE);
33 logAction(`Decremented by ${step}`, prev, next);
34 return next;
35 });
36 };
37 
38 const handleReset = () => {
39 logAction('Reset to zero', count, 0);
40 setCount(0);
41 };
42 
43 const handleStepChange = (e) => {
44 const parsed = parseInt(e.target.value, 10);
45 setStep(isNaN(parsed) || parsed < 1 ? 1 : parsed);
46 };
47 
48 const isAtMin = count <= MIN_VALUE;
49 const isAtMax = count >= MAX_VALUE;
50 
51 return (
52 <div className="counter-container">
53 <h2>Interactive Step Counter</h2>
54 
55 {/* Main Display */}
56 <div className={`count-badge ${count > 0 ? 'positive' : count < 0 ? 'negative' : 'neutral'}`}>
57 <span className="count-number">{count}</span>
58 </div>
59 
60 {/* Limit Warnings */}
61 {isAtMax && <p className="warning-text">Reached maximum limit of {MAX_VALUE}!</p>}
62 {isAtMin && <p className="warning-text">Reached minimum limit of {MIN_VALUE}!</p>}
63 
64 {/* Controls */}
65 <div className="controls-box">
66 <label>
67 Step Size:
68 <input
69 type="number"
70 min="1"
71 max="25"
72 value={step}
73 onChange={handleStepChange}
74 className="step-input"
75 />
76 </label>
77 
78 <div className="button-row">
79 <button onClick={handleDecrement} disabled={isAtMin} className="btn btn-secondary">
80 - {step}
81 </button>
82 <button onClick={handleReset} className="btn btn-outline">
83 Reset
84 </button>
85 <button onClick={handleIncrement} disabled={isAtMax} className="btn btn-primary">
86 + {step}
87 </button>
88 </div>
89 </div>
90 
91 {/* Audit History Log */}
92 {history.length > 0 && (
93 <div className="history-section">
94 <h4>Recent Activity</h4>
95 <ul className="history-list">
96 {history.map((item) => (
97 <li key={item.id}>
98 <span className="timestamp">[{item.time}]</span> {item.description}
99 </li>
100 ))}
101 </ul>
102 </div>
103 )}
104 </div>
105 );
106}

3. Key Architecture Concepts Illustrated

  1. 1
    Functional State Updates: setCount(prev => ...) ensures accurate arithmetic even during rapid user clicks.
  2. 2
    Immutable Array History: setHistory(prev => [entry, ...prev]) prepends new log entries immutably without mutating previous history.
  3. 3
    Derived Boundary Disabling: isAtMin and isAtMax are computed values during render, cleanly disabling buttons when limits are reached.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why is Math.min(prev + step, MAX_VALUE) used when incrementing the counter?
Question 2
How does the component limit the history log to the most recent 10 events?
Question 3
What is the benefit of computing isAtMin = count <= MIN_VALUE during render instead of storing isAtMin in a separate useState?
Question 4
Why is parseInt(e.target.value, 10) paired with isNaN checking in handleStepChange?
Question 5
What HTML attribute is used to disable the increment button when the maximum threshold is reached?
Next Lesson

Mini Project: Dynamic FAQ Accordion

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Utility-First Styling with Tailwind CSS in ReactMini Project: Dynamic FAQ Accordion

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext