VOOZH about

URL: https://www.geeksforgeeks.org/reactjs/create-a-stop-watch-using-reactjs/

⇱ Create a Stop Watch using ReactJS - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Create a Stop Watch using ReactJS

Last Updated : 23 Jul, 2025

We can create Stop Watch in ReactJS using the following approach. Our StopWatch will have the functionality of Start, Pause, Resume and Reset.

Creating React Application And Installing Module:

Step 1: Create a React application using the following command.

npm create vite@latest stopwatch --template react

Step 2: After creating your project folder i.e. stopwatch, move to it using the following command.

cd stopwatch

Step 3: Install project dependencies.

After initializing your Vite project, install the required dependencies by running:

npm install

Create a Components folder insider the src folder. Inside the Components folder create three different subfolders with the names StopWatch, Timer, ControlButtons. Now make a .jsx and a .css for each components.

Project Structure: It will look like the following.

👁 Image

Components used in our applications are:

👁 Image

Example: The outer component is StopWatch, the blue marked is the Timer, and the green-colored component will be denoted as ControlButtons.

index.js

App.js

App.css

StopWatch.jsx

StopWatch.css

Three states used in the StopWatch component.

  • time: It stores the time elapsed since you pressed start.
  • isActive: It tells if the stop watch is in active state (i.e it is running, or it is being paused).
  • isPaused: It tells if the stop watch is in active state and is paused or not.

Timer.jsx

Timer.css

ControlButtons.jsx

ContolButtons.css

ControlButtons Rendering: If user haven't started the stop watch then you are supposed to show only the start button. If the user have started the stop watch then you are supposed to show the reset and resume/pause buttons.

Step to Run Application: Run the application using the following command from the root directory of the project.

npm run dev 

Output: Now open your browser and go to http://localhost:5173/, you will see the following output.

👁 Image

Comment