🧑💻 Today present a remarkable React countdown timer that will leave your visitors spellbound. Whether you're running a flash sale, promoting a limited-time offer, or counting down to a grand product launch, this beautiful timer is the secret weapon to captivate, engage, and convert.
Let's dive into the enchanting world of our React countdown timer and discover how it can transform your promotional campaigns into unforgettable experiences.
So first of all setup the project. We will create a react project using vite.
npm create vite@latest countdown-time -- --template react
cd countdown-time
npm install
npm install react-countdown
npm run dev
No remove all the unnecessary code from the app.jsx
file -
Now on app.jsx
file I wrote this code -
import './App.css';
import Countdown from 'react-countdown';
function App() {
return (
<div>
<Countdown date={Date.now() + 10000000} />
</div>
);
}
export default App;
And the output (screenshot) is -
Custom & Conditional Rendering
In case you want to change the output of the component or want to signal that the countdown's work is done, you can do this by either using the onComplete
callback, a custom renderer, or by specifying a React child within <Countdown></Countdown>
, which will only be shown once the countdown is complete.
Example -
import './App.css';
import Countdown from 'react-countdown';
const Completionist = () => <span>Time Finish!! You are good to go!</span>;
function App() {
return (
<div>
<Countdown date={Date.now() + 5000}>
<Completionist />
</Countdown>
</div>
);
}
export default App;
And after the time is finish , it will hide the timer and show a message like this -
You can add style as you like. For example for one of my project I have make this countdown timer below using tailwind CSS.
See? This react-countdown
package is awesome and it has more awesome use case. Like Sales, Marketing, Exam Scheduling, Ticket Selling and many more.
You can read more details about this on their official documentation..
Thank you so much for reading.❤️
Top comments (0)