将javascript切换为React native JS
我在js vanilla中实现了这个功能,但现在我正在使用react native。有人能帮我在react native js上切换这个代码吗?谢谢,这是事先准备好的将javascript切换为React native JS,javascript,react-native,Javascript,React Native,我在js vanilla中实现了这个功能,但现在我正在使用react native。有人能帮我在react native js上切换这个代码吗?谢谢,这是事先准备好的 TimerDecibels = () => { return this.state.sport.clubs.map((element) => { // Set the date we're counting down to var countDownDate = new Date(ele
TimerDecibels = () => {
return this.state.sport.clubs.map((element) => {
// Set the date we're counting down to
var countDownDate = new Date(element.dateStopMatch).getTime();
// Update the count down every 1 second
var x = setInterval(function () {
// Get today's date and time
var now = new Date(element.dateMatch).getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor(
(distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60),
);
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an element with id="demo"
document.getElementById('demo').innerHTML =
days + 'd ' + hours + 'h ' + minutes + 'm ' + seconds + 's ';
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById('demo').innerHTML = 'EXPIRED';
}
}, 1000);
});
};
TimerDecibels=()=>{
返回此.state.sport.clubs.map((元素)=>{
//确定我们倒计时的日期
var countDownDate=新日期(element.dateStopMatch.getTime();
//每1秒更新一次倒计时
var x=设置间隔(函数(){
//获取今天的日期和时间
var now=新日期(element.dateMatch).getTime();
//找出现在和倒计时日期之间的距离
var距离=倒计时日期-现在;
//天、小时、分钟和秒的时间计算
变量天数=数学楼层(距离/(1000*60*60*24));
var小时=数学楼层(
(距离%(1000*60*60*24))/(1000*60*60),
);
var分钟=数学楼层((距离%(1000*60*60))/(1000*60));
var秒=数学楼层((距离%(1000*60))/1000);
//在id=“demo”的元素中输出结果
document.getElementById('demo').innerHTML=
天+小时+小时+分钟+米+秒+秒;
//如果倒计时结束,写一些文字
如果(距离<0){
净间隔(x);
document.getElementById('demo').innerHTML='EXPIRED';
}
}, 1000);
});
};
在JS中也不是React Native。大多数普通的JS代码在React Native中不应该工作得很好吗?我不是react方面的专家,如果我错了,请纠正我。@JonahCRowlinson是一个Javascript库。应该没有区别。@JonahCRowlinson没有文档。getElementById
是React-Native。@Titus啊,好吧,不知道是什么。我是这么想的,但document.getElementById似乎无法呈现倒计时:/