- Replace
<your_account>
with your Github username in the DEMO LINK - Follow the React task guideline
- Use React TypeScript cheat sheet
Create a Clock
component updating the time every second.
- Use class component
- Start the timer only when the component is added to the page (
componentDidMount
) - Update the
state
every second usingsetInterval
- Save timerId to stop it later
this.timerId = setInterval(your code here);
- Watch this video about HOW TO HANDLE BUTTON CLICK.
- Add buttons
Show Clock
andHide Clock
in theApp
component to changeisClockVisible
variable in theApp
state. - The
Clock
should not be rendered whenisClockVisible
isfalse
. - You have to add
data-cy="time"
attribute to the element, which show time on the page - Change the
Clock
component to print the time not only on the page but also in theDevTools
console.- Stop the timer when the
Clock
is hidden (componentWillUnmount
)// use previously saved timerId clearInterval(this.timerId);
- Stop the timer when the
- Check if it works correctly:
- Hide and show the
Clock
several times and leave it visible - The time in the console should be printed only once each second
- Hide and show the
- Add
Set random name
button to theApp
to set a random number as aclockName
variable in theApp
state. - Pass the name to the
<Clock name={this.state.clockName} />
- Every time the
name
changes print a message in the consoleThe Clock was renamed from oldName to newName
(componentDidUpdate
)- Check if the message appears in the console between clock ticks