0
나는 React Native에서 간단한 카운트 다운을하려고합니다. TimerMixin을 사용했지만 아무것도 업데이트하지 않았습니다.React Native Timer not triggering
타이머가 시간 제한을 실행하지 않는 이유가 확실하지 않습니다.
import React from 'react-native'
var TimerMixin = require('react-timer-mixin');
var reactMixin = require('react-mixin');
const {
Dimensions,
StyleSheet,
ScrollView,
View,
Image,
Text,
Component,
} = React;
class Countdown extends Component {
constructor() {
super();
this.state = {
targetDate: "09/09/2016",
time: {
total: 0,
days: 0,
hours: 0,
minutes: 0,
seconds: 0
}
}
}
componentDidMount() {
this.timer = TimerMixin.setTimeout(() => {
console.log('Refreshing ' + this.state.time.seconds);
this.refresh();
},100);
}
componentWillUnmount() {
TimerMixin.clearTimeout(this.timer);
}
refresh() {
var t = Date.parse(this.state.targetDate) - Date.parse(new Date());
var seconds = Math.floor((t/1000) % 60);
var minutes = Math.floor((t/1000/60) % 60);
var hours = Math.floor((t/(1000*60*60)) % 24);
var days = Math.floor(t/(1000*60*60*24));
var time = {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
this.setState({targetDate: this.state.targetDate, time: time});
}
render() {
// Render omitted for simplicity of question
}
}
reactMixin(Countdown.prototype, TimerMixin);
module.exports = Countdown;
내가 한 번만 초기화에 "새로 고침 0"을 얻을
.