React Textarea — Character Counter with Max Length

Forms & Events — Beginner React challenge.

Build a controlled textarea with a live character counter and a max-length guard from scratch: typing, pasting, and clearing all stay in sync with the counter — no libraries, no pre-built markup.

Requirements

Signature

function CharCounterTextarea({ maxLength: number }): JSX.Element

Example

<CharCounterTextarea maxLength={200} />
// type "Hello world" -> textarea shows it, counter shows "11 / 200"
// paste 14 chars into a maxLength=10 field -> clamped to 10, counter turns red
// click Clear -> textarea empty, counter "0 / 200", normal color

Constraints

🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code
Loading workspace…