React Machine Coding Series – Part 3: Countdown Timer with Normalized Time
Edition Overview
In this edition of my React Machine Coding Series, I’m building a countdown timer from scratch using React.
The focus is on correct state modeling, time normalization, and clean side-effect handling. Timers look simple, but they reveal many subtle issues when not designed carefully.
Problem Description
Create a countdown timer with:
Functional Behavior
Button state transitions
Countdown logic
Time normalization
User input is normalized before the timer starts.
Examples:
This keeps the logic predictable and reliable.
Design Approach
Single source of truth
The timer is driven by a single value called totalSeconds.
Hours, minutes, and seconds are derived from it.
This avoids state mismatches and keeps the countdown logic simple.
Recommended by LinkedIn
Normalization before execution
All input values are converted into total seconds before starting the timer.
This ensures:
Side-effect management with useEffect
Two effects are used:
Cleanup is handled correctly to prevent multiple intervals or memory leaks.
Demo gif :
Tech Stack
No external libraries were used.
Key Takeaways
Github Code link : Github link
What’s Next
In the next edition, I’ll continue building on this series with more React components that focus on clarity, correctness, and maintainability.
Closing Note
This series is part of my ongoing effort to learn in public and write clean, understandable React code.
If you found this useful, feel free to like, share, or add your thoughts in the comments.
#interested connect to via View my profile linked in