Question

In: Computer Science

Create a timer in REACT JS using any library application which asks the user for minutes....

  1. Create a timer in REACT JS using any library application which asks the user for minutes. The user then click Start button and starts the timer count down.

Solutions

Expert Solution

Hi,

Please add this code in HTML:

<div id="timer"></div>

Please add the below code in JS file:

class Timer extends React.Component {
constructor (props) {
super(props)
this.state = {count: 1}
}
componentWillUnmount () {
clearInterval(this.timer)
}
tick () {
this.setState({count: (this.state.count + 1)})
}
startTimer () {
clearInterval(this.timer)
this.timer = setInterval(this.tick.bind(this), 1000)
}
stopTimer () {
clearInterval(this.timer)
}
render () {
return (
<div className='timer'>
<h1>{this.state.count}</h1>
<div>
<label>
Enter the minutes:
<input type="text" name="name" />
</label><br />
<button onClick={this.startTimer.bind(this)}>Start</button> <button onClick={this.stopTimer.bind(this)}>Stop</button>
</div>
</div>
)
}
}

ReactDOM.render(
<Timer />,
document.getElementById('timer')
)

Please let me know if you any questions.

Happy Learning!


Related Solutions

Create an application for a library and name it FineForOverdueBooks. TheMain() method asks the user to...
Create an application for a library and name it FineForOverdueBooks. TheMain() method asks the user to input the number of books checked out and the number of days they are overdue. Pass those values to a method named DisplayFine that displays the library fine, which is 10 cents per book per day for the first seven days a book is overdue, then 20 cents per book per day for each additional day. The library fine should be displayed in the...
Use JQuery or any other JS library to perform the following – 1pt Create a JS...
Use JQuery or any other JS library to perform the following – 1pt Create a JS based menu – 3pt a. This can be as simple or complex as you want, from having JS change the colors of the links to flyout type menus or anything else you want. Create a slideshow – 3pt Create another interactive JS component (your choice) – 3pt a. When submitting the link to the page, describe what your choice was to ensure I see...
Create an application named Rusty2 that asks the user for the dealer cost of a car,...
Create an application named Rusty2 that asks the user for the dealer cost of a car, and the cleaning cost, and then displays the retail cost. Your application should simply send the dealer cost and cleaning cost to the getRetailPrice method in the Dealership class to obtain the retail cost. here below is the dealership class code amd meed to create rusty2 code import java.util.Calendar; public class Dealership { // public static final class variables public static final int YEAR_STARTED...
Create an application that asks a user to answer 5 math questions. JAVA
Create an application that asks a user to answer 5 math questions. JAVA
How to create a JS application using the code below that displays the lists of grades...
How to create a JS application using the code below that displays the lists of grades in their corresponding letter grade textbox and each grade being sorted from lowest to highest. <!DOCTYPE> <html> <head> <title>EXAM01_03</title> <style type="text/css"> form{color:black;background-color:lightgray;border:6px solid black;border-width:4px;width:450px;margin:1px;padding:1px;} #ans1,#ans2,#ans3,#ans4,#ans5,#numbers{background-color:white;border:4px solid black;} input[type="button"]{color:black;background-color:red;border:4px solid black;} input[type="text"]{margin:2px;} div.title{color:white;background-color:black;float: left; width: 450px; text-align:center;} </style> </head> <body>    <form>    <div class="title"><label>EXAM01_03</label></div>    <p style="clear:both;" />    <div style="float:left;width:150px;"><label>Enter Grade List:</label></div><div style="float:left;"><input type="text" id="numbers" /></div>    <p style="clear:both;" />    <div style="float:left;width:150px;"><label>A:</label></div><div...
C# Create an application that asks the user to enter their new password. The password must...
C# Create an application that asks the user to enter their new password. The password must be at least 6 characters long. Develop a custom exception handling case that checks for the password length. (hint: use " .Length " built-in method). If the new password is less than 6 characters long the custom exception should output an error message.
Create any IOS mobile application using swift that can do the following A user should be...
Create any IOS mobile application using swift that can do the following A user should be able to see all uncompleted tasks in a UITableView • A user should be able to create new tasks • A user should be able to edit a task • A user should be able to mark a task as complete • A user should be able to see all completed tasks in a UITableView • A user should be able to close and...
C# Create a console application that asks the user for two numbers in the range 0-255...
C# Create a console application that asks the user for two numbers in the range 0-255 and then divides the first number by the second: Enter a number between 0 and 255: 100 Enter another number between 0 and 255: 8 100 divided by 8 is 12 Enter a number between 0 and 255: apples Enter another number between 0 and 255: bananas FormatException: Input string was not in a correct format.
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any...
Create a Web Page Using HTML, CSS, JS, jQuery • Create a web profile, including any of the following: • Your hobbies, likes/dislikes, career aspirations, dream job, favorite animals/ pets, favorite superhero, etc. • You do not have to share personal information that you are uncomfortable with sharing. Follow these guidelines when creating your page: • Include at least one heading (h1, h2, etc.) in your web page. • Provide a quote from a book, movie, etc. • Include at...
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT