setInterval関数が時間を減らさない理由を知りたかっただけです.... isnt setIntervalは関数を何度も何度もやり直すことを想定していますか?私は100に入れ、プレス提出した場合、それはこれがapp.jsx [ファイル] - ユーザーがここで秒単位で番号を入力すると、それは、クロックに行くで1反応カウントダウンアプリにこだわり、setIntervalを適切に利用する方法を知りたがっています
class Clock extends Component{
constructor(props){
super(props);
this.state = {
seconds: 60,
}
console.log('this.props',this.props);
console.log('seconds', this.state.seconds);
}
componentWillMount(){
this.timer(this.props.time);
}
componentDidMount(){
setInterval(()=> this.timer(this.props.time),1000);
}
timer(time){
console.log('new time',time)
this.setState({seconds:time-1});
}
render(){
return (
<div>
<div className="Clock-seconds">{this.state.seconds} seconds</div>
</div>
)}}
でダウン1行くことを期待していた 小道具私は州で時間があります。
import React, {Component} from 'react';
import Clock from './Clock';
import './App.css';
import {Form, FormControl, Button} from 'react-bootstrap';
class App extends Component{
constructor(props){
super(props);
this.state ={
time: '60',
newTime: ''
}
}
changeTime(){
this.setState({time: this.state.newTime});
}
render(){
return (
<div className="App">
<div className = "App-title">
Countdown to {this.state.time}
</div>
<Clock
time={this.state.time}
/>
<Form inline >
<FormControl
className="Deadline-input"
placeholder='new date'
onChange={event => this.setState({newTime: event.target.value})}
/>
<Button onClick={() => this.changeTime()}>
Submit
</Button>
</Form>
</div>
)
}
}
export default App;
https://stackoverflow.com/questions/36299174/setinterval-in-a-react-app?rq=1 –