Recreate a stopwatch in React. Your final product should function similarly to this deployed version of the component.
- Fork and clone this repo
- Once you have the app locally, install necessary dependencies with
$ npm install
- Start the development server locally with
$ npm start
, then visitlocalhost:3000
in the browser to view app
Take the existing markup rendered from the Stopwatch
component in src/Stopwatch.js
and change into a fully functioning component. This means that you only have to add functionality -- not markup or styling -- to the existing code!
-
Add a
constructor
method and initialize state with acounter
property to track the incrementing time. (You may need additional state properties later on) -
Create a
handleStart
method that calls setInterval() and updatescounter
every second. (Make sure to usesetState
to update) -
Include an
onClick
attribute on the start button which callshandleStart
-
Replace the
0
in theh1
heading with yourcounter
. -
Next you will need to create
onClick
event attributes for reset and pause and associated methods for each.
Hints...Shhhhhh!
You will also most likely need to include an additional attribute in your constructor method that keeps track of your current interval. If you have an active interval, then don't let the start button be fired again!
You can use
clearInterval
to stop the current interval!
- When the stopwatch is at 0, the display time should be a different style.
- When the user first visits the page, the only button that should be active is "Start".
- The other buttons should be unlocked only after the user clicks "start"
- Have multiple Stopwatch components rendered on the page so the User can set off multiple timers.