🕒 Build a Pomodoro Timer App with Next.js — Step-by-Step Guide
@achidi_malik · · 2 min read
Do you struggle with staying focused while coding or studying? The Pomodoro Technique is a time-management method that helps boost productivity by breaking work into 25-minute focused sessions followed by 5-minute breaks. And today, we’re going to build our own Pomodoro App using Next.js!
🚀 What You’ll Learn
• React Hooks (useState & useEffect)
• Component-based architecture in Next.js
• Creating timers and handling intervals
• Optional: Tailwind CSS and deployment on Vercel
🛠️ Tech Stack
• Next.js (React Framework)
• Tailwind CSS
• JavaScript / TypeScript
📦 Step 1: Setting Up the Project
npx create-next-app@latest pomodoro-app
cd pomodoro-app
npm installOn installation you can add tailwind css
npm install -D tailwindcss postcss autoprefixernpx tailwindcss init -pConfigure your tailwind.config.js and add Tailwind to global.css
🧱 Step 2: Basic Component Structure
Create a component called PomodoroTimer.js in /components.
import { useState, useEffect } from 'react';
export default function PomodoroTimer() {
const [secondsLeft, setSecondsLeft] = useState(25 * 60); // 25 mins
const [isRunning, setIsRunning] = useState(false);
useEffect(() => {
let interval = null;
if (isRunning) {
interval = setInterval(() => {
setSecondsLeft(prev => (prev > 0 ? prev - 1 : 0));
}, 1000);
} else {
clearInterval(interval);
}
return () => clearInterval(interval);
}, [isRunning]);
const formatTime = (secs) => {
const minutes = Math.floor(secs / 60);
const seconds = secs % 60;
return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
};
return (
<div className="text-center p-4">
<h1 className="text-4xl font-bold mb-4">Pomodoro Timer</h1>
<div className="text-6xl font-mono">{formatTime(secondsLeft)}</div>
<div className="mt-6">
<button
onClick={() => setIsRunning(!isRunning)}
className="bg-blue-600 text-white px-4 py-2 rounded mr-2"
>
{isRunning ? 'Pause' : 'Start'}
</button>
<button
onClick={() => {
setIsRunning(false);
setSecondsLeft(25 * 60);
}}
className="bg-red-600 text-white px-4 py-2 rounded"
>
Reset
</button>
</div>
</div>
);
}
🧩 Step 3: Use the Component
Replace the existing index.js with:
import Head from 'next/head';
import PomodoroTimer from '../components/PomodoroTimer';
export default function Home() {
return (
<>
<Head>
<title>Pomodoro App</title>
</Head>
<main className="min-h-screen flex items-center justify-center bg-gray-100">
<PomodoroTimer />
</main>
</>
);
}🌟 Step 4: Add Break Mode (Optional)
const [mode, setMode] = useState('work'); // 'work' or 'break'
useEffect(() => {
if (secondsLeft === 0 && isRunning) {
setIsRunning(false);
if (mode === 'work') {
setMode('break');
setSecondsLeft(5 * 60);
} else {
setMode('work');
setSecondsLeft(25 * 60);
}
}
}, [secondsLeft, isRunning]);
🚀 Step 5: Deploy to Vercel
npx vercelYou’ve just built a working Pomodoro Timer with Next.js! This is a great example of using React for real-time updates, managing side effects with hooks, and deploying a fully functional productivity tool.
Want more ideas?
Try:
- Adding a stats dashboard
- Using Firebase or Supabase for login
- Gamifying the timer with experience points
1 Reply4 Likes





