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: Real-Time Character Counter and Text Utility0%
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: Real-Time Character Counter and Text Utility
Understanding Common React Errors and Warnings

Mini Project: Real-Time Character Counter and Text Utility

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

1. Project Overview & Requirements

In this mini-project, we will engineer a high-utility Real-Time Character Counter and Text Utility application.

This project demonstrates the power of controlled inputs, derived state calculations, and clipboard interactions:

  1. 1
    Real-Time Metrics: Compute total characters, characters excluding whitespace, total words, sentences, and estimated reading time on every keystroke.
  2. 2
    Character Limit & Warning: Set an optional maximum character limit (e.g. 280 characters for Twitter/X) with dynamic progress bar and color threshold warnings.
  3. 3
    Text Case Transformations: Provide instant transformations (UPPERCASE, lowercase, Title Case, and Whitespace Trimming).
  4. 4
    Copy to Clipboard: Allow users to copy the transformed text with instant visual feedback.
1┌────────────────────────────────────────────────────────┐
2│ Real-Time Text Intelligence │
3│ │
4│ [ Textarea: Type or paste content here... ] │
5│ │
6│ Progress: [████████████░░░░░░░░] 142 / 280 chars │
7│ │
8│ [ 24 Words ] [ 142 Chars ] [ 1m Read ] [ 2 Sent ] │
9│ │
10│ [ UPPERCASE ] [ lowercase ] [ Trim ] [ Copy ] │
11└────────────────────────────────────────────────────────┘

2. Component Implementation

1import React, { useState } from 'react';
2 
3const MAX_LIMIT = 280;
4 
5export default function TextUtility() {
6 const [text, setText] = useState('');
7 const [copied, setCopied] = useState(false);
8 
9 // Derived metrics (computed on the fly during render!)
10 const charCount = text.length;
11 const charsNoSpaces = text.replace(/\s+/g, '').length;
12 const wordCount = text.trim() === '' ? 0 : text.trim().split(/\s+/).length;
13 const sentenceCount = text.trim() === '' ? 0 : text.split(/[.!?]+/).filter(Boolean).length;
14 const readingTimeMinutes = Math.ceil(wordCount / 200); // Avg reading speed 200 wpm
15 
16 const remainingChars = MAX_LIMIT - charCount;
17 const percentUsed = Math.min((charCount / MAX_LIMIT) * 100, 100);
18 
19 // Transformations
20 const handleUppercase = () => setText(text.toUpperCase());
21 const handleLowercase = () => setText(text.toLowerCase());
22 const handleTrimSpaces = () => setText(text.replace(/\s+/g, ' ').trim());
23 const handleClear = () => setText('');
24 
25 const handleCopy = async () => {
26 if (!text) return;
27 await navigator.clipboard.writeText(text);
28 setCopied(true);
29 setTimeout(() => setCopied(false), 2000);
30 };
31 
32 return (
33 <div className="utility-card">
34 <h2>Text Analytics & Transformation Studio</h2>
35 
36 {/* Controlled Textarea */}
37 <textarea
38 rows={5}
39 value={text}
40 onChange={(e) => setText(e.target.value)}
41 placeholder="Type or paste your text here..."
42 className={`text-input ${charCount > MAX_LIMIT ? 'input-over-limit' : ''}`}
43 />
44 
45 {/* Progress Bar */}
46 <div className="progress-bar-container">
47 <div
48 className={`progress-fill ${percentUsed >= 100 ? 'bg-danger' : percentUsed >= 80 ? 'bg-warning' : 'bg-primary'}`}
49 style={{ width: `${percentUsed}%` }}
50 />
51 </div>
52 
53 <div className="limit-info">
54 <span>{charCount} / {MAX_LIMIT} characters</span>
55 <span className={remainingChars < 0 ? 'text-danger font-bold' : ''}>
56 {remainingChars >= 0 ? `${remainingChars} remaining` : `${Math.abs(remainingChars)} characters over limit`}
57 </span>
58 </div>
59 
60 {/* Metrics Row */}
61 <div className="metrics-grid">
62 <div className="metric-box">
63 <span className="metric-val">{wordCount}</span>
64 <span className="metric-lbl">Words</span>
65 </div>
66 <div className="metric-box">
67 <span className="metric-val">{charsNoSpaces}</span>
68 <span className="metric-lbl">No Spaces</span>
69 </div>
70 <div className="metric-box">
71 <span className="metric-val">{sentenceCount}</span>
72 <span className="metric-lbl">Sentences</span>
73 </div>
74 <div className="metric-box">
75 <span className="metric-val">~{readingTimeMinutes} min</span>
76 <span className="metric-lbl">Read Time</span>
77 </div>
78 </div>
79 
80 {/* Actions Toolbar */}
81 <div className="toolbar">
82 <button onClick={handleUppercase} disabled={!text}>UPPERCASE</button>
83 <button onClick={handleLowercase} disabled={!text}>lowercase</button>
84 <button onClick={handleTrimSpaces} disabled={!text}>Trim Spaces</button>
85 <button onClick={handleClear} disabled={!text} className="btn-danger">Clear</button>
86 <button onClick={handleCopy} disabled={!text} className="btn-copy">
87 {copied ? '✓ Copied!' : 'Copy to Clipboard'}
88 </button>
89 </div>
90 </div>
91 );
92}

3. Key React Lessons Applied

  1. 1
    Zero Redundant State: Notice we did not create separate state variables for wordCount, charCount, or readingTime. All of these are calculated derived values computed cleanly during render.
  2. 2
    Asynchronous Clipboard API: Using navigator.clipboard.writeText(text) allows native browser copying, followed by a temporary 2-second visual confirmation via setTimeout.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why were wordCount, charCount, and sentenceCount NOT placed inside separate useState variables?
Question 2
How is the progress bar fill width dynamically applied to the element?
Question 3
How is the temporary "Copied!" feedback message cleared after 2 seconds?
Question 4
What does text.trim().split(/\s+/).length achieve when calculating word count?
Question 5
Why is disabled={!text} applied to the transformation buttons?
Next Lesson

Understanding Common React Errors and Warnings

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

Related Lessons

Previous LessonNext Lesson
Mini Project: Dynamic FAQ AccordionUnderstanding Common React Errors and Warnings

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