How to add Timer in Next.js ?
Last Updated :
30 Jul, 2024
In this article, we are going to learn how we can add Timer in NextJS. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components conditionally.
Approach
To add our Timer we are going to use the react-countdown-circle-timer package. The react-countdown-circle-timer package helps us to integrate different types of timers. So first, we will install the react-countdown-circle-timer package, and then we will add timer on our homepage.
Create NextJS Application
You can create a new NextJs project using the below command:
npx create-next-app gfg
Install the required package: Now we will install the react-countdown-circle-timer package using the below command:
npm i react-countdown-circle-timer
Project Structure: It will look like this.

The updated dependencies in packasge.json file:
"dependencies": {
"next": "14.2.4",
"react": "^18",
"react-countdown-circle-timer": "^3.2.1",
"react-dom": "^18",
}
Example: This example demonstrates timer in Next.js using the react-countdown-circle-timer package.
JavaScript
// Filename - index.js
import { CountdownCircleTimer } from "react-countdown-circle-timer";
export default function Timer() {
return (
<div>
<h3>GeeksforGeeks - Timer</h3>
<CountdownCircleTimer
isPlaying
duration={10}
colors={[
["#004777", 0.33],
["#F7B801", 0.33],
["#A30000", 0.33],
]}
>
{({ remainingTime }) => remainingTime}
</CountdownCircleTimer>
</div>
);
}
Explanation: In the above example first, we are importing our CountdownCircleTimer component from the installed package. After that, we are using the component and set the initial properties like isPlaying, duration, and color. Then we are displaying the remainingTime.
Steps to run the application: Run the below command in the terminal to run the app.
npm run dev
Output:
Similar Reads
How to Add Tweets in Next.js ? Adding tweets in Next.js involves using Twitter's embed feature or API to display tweets. You can embed tweets directly in components or fetch and display them using server-side rendering or client-side data fetching. In this article, we are going to learn how we can add Tweets in NextJs.ApproachTo
2 min read
How to add ESLint in Next.js ? ESLint is a popular linting tool for identifying and fixing issues in JavaScript code. Adding ESLint to your Next.js project ensures that your code follows best practices and maintains a consistent style. This enhances code quality, helps catch errors early, and makes the codebase easier to maintain
3 min read
How to add Calendar in Next.js ? Adding a calendar to a Next.js application enhances scheduling and event management. We can just install and use the available npm package. In this article, we are going to learn how we can add a calendar loader in NextJS.ApproachTo add our calendar we are going to use the react-calendar package. Th
2 min read
How to Set Time Delay in JavaScript? Delaying the execution of code is a fundamental technique that is commonly used in JavaScript for tasks like animations, API polling, or managing time intervals between actions. JavaScript provides several built-in methods to set time delays: setTimeout() and setInterval(). We can set time delay in
2 min read
How to Display Time in NuxtJS ? In this article, we are going to learn how we can show time in NuxtJs. Nuxt.js is a free and open-source web application framework based on Vue.js, Node.js, Webpack, and Babel.js. Nuxt is inspired by Next.js, which is a framework of similar purpose, based on React.js. Approach: To show time in nuxtj
2 min read