我在我的项目中使用了 Countdown 和 ReactCodeInput 并且它有效。但是当我将它与简单的输入结合起来时,只要我的输入发生变化,它就会重新启动。我只想重新启动它,并且只有在时间结束时才重新启动它。这是我的代码:
import React, { Component } from "react";
import Countdown from "react-countdown-now";
import ReactCodeInput from "react-code-input";
const lengthToken = 6;
class Test extends Component {
constructor(props) {
super(props);
this.state = {
token: "",
secondsToExpire: 600000
};
}
saveTokenToState = token => {
this.setState({ token });
};
render() {
const renderer = ({ minutes, seconds }) => (
<span>
{minutes}:{seconds}
</span>
);
return (
<div>
<label htmlFor="token">
<ReactCodeInput
inputmode="numeric"
pattern="[0-9]*"
type="number"
name="test"
fields={lengthToken}
value={this.state.token}
onChange={this.saveTokenToState}
inputStyle={codeStyle}
/>
</label>
<Countdown
renderer={renderer}
date={Date.now() + this.state.secondsToExpire}
/>
</div>
);
}
}
繁星coding
手掌心
ABOUTYOU
相关分类