Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 13, 2022 05:07 am GMT

How to Make Stopwatch in React

In this article, we are going to make a stopwatch in react. Like a basic stopwatch we will have a display to show time, then we will have basic buttons for start, stop, resume and reset. As soon we will hit the start button, timer will be started and two buttons will appear stop and reset. By clicking stop, the timer will be stopped, and a resume button will appear. Lastly, the reset button will reset the timer back to 0 again.

So basically this is going to be a beginner-friendly project, so lets make this project step-by-step.

Pre-requisites to Make Stopwatch in React

  • Basic knowledge of ReactJS.
  • Basic knowledge of React hooks.
  • Basic knowledge of React props.
  • Good knowledge of React Components.

Creating App Component

Let us start with App.js component, we have imported DisplayComponent.js and BtnComponent.js components, in which we will add structure for button and display. Then we also imported useState hook, so we can make use of it to get variable time. Now we have created state for time with initial 0 values for ms,s,m,h, which is actually for millisecond, second,minute and hour.

Then in return statement, we have called these two components in a div. And we have passed time as a prop for . Okay, so this is not for all for App.js we will do some changes as we progress in the Application.
Read More

Then in return statement, we have called these two components in a div. And we have passed time as a prop for . Okay, so this is not for all for App.js we will do some changes as we progress in the Application.

)


Original Link: https://dev.to/reactjsguru/how-to-make-stopwatch-in-react-49l8

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To