REACT create alarm clock react - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution

create alarm clock using react


 1871

REACT


2

import React from "react";

class App extends React.Component {
constructor() {
super();
this.state = {
currentTime: '',
alarmTime: ''
};
this.Set_Alarm_Time = this.Set_Alarm_Time.bind(this);
}

componentDidMount(){
this.clock = setInterval(
() => this.Set_Current_Time(),
1000
)
this.interval = setInterval(
() => this.checkAlarmClock(),
1000)
}

componentWillUnmount(){
clearInterval(this.clock);
clearInterval(this.interval);
}

Set_Current_Time(){
this.setState({
currentTime: new Date().toLocaleTimeString('en-US', { hour12: false })
});
}

Set_Alarm_Time(event) {
event.preventDefault();
const inputAlarmTimeModified = event.target.value + ':00'
this.setState({
alarmTime: inputAlarmTimeModified
})
}

checkAlarmClock(){
if(this.state.alarmTime == 'undefined' || !this.state.alarmTime) {
this.alarmMessage = "Pls set your alarm.";
} else {
this.alarmMessage = "Your alarm is set for " + this.state.alarmTime + ".";
if(this.state.currentTime === this.state.alarmTime) {
alert("its time!");
} else {
console.log("not yet");
}
}
}

render() {
return (
<div>
<h1>Your Alarm Clock</h1>
<h2>currentTime: {this.state.currentTime}.
</h2>
<h2>{this.alarmMessage}
</h2>
<form>
<input type="time" onChange={this.Set_Alarm_Time}></input>
</form>
</div>
);
}
}

export default App;


By     Created   
The power of the user (%)
10%



The most helpful REACT solutions

How to get client ip address using react ?How to get client ip address using react ?REACT

Click to see more ...

  4.2K     418

how to get the type of a device using react ?how to get the type of a device using react ?REACT

Click to see more ...

  1.3K     203

country dropdown using reactcountry dropdown using reactREACT

Click to see more ...

  794     127

How to get latitude and longitude using react/javascript ?How to get latitude and longitude using react/javascript ?REACT

Click to see more ...

  581     104

get ip address reactget ip address reactREACT

Click to see more ...

  342     80

time ago reacttime ago reactREACT

Click to see more ...

  275     73

detect mobile device reactdetect mobile device reactREACT

Click to see more ...

  234     58

get client country reactget client country reactREACT

Click to see more ...

  227     53

how to detect a mobile device not tablet using react ?how to detect a mobile device not tablet using react ?REACT

Click to see more ...

  216     51

detect browser reactdetect browser reactREACT

Click to see more ...

  228     36