Convert your inputs to be controlled inputs and pad the input's value
prop.
value={hours.padStart(2, '0')}
Code
const SetTimer = () => {
const [hours, setHours] = useState("");
const [minutes, setMinutes] = useState("");
const [seconds, setSeconds] = useState("");
return (
<div className="grid-inputs">
<div>
<label htmlFor="hours">Hours</label>
<input
name="hours"
type="number"
min="0"
max="99"
value={hours.padStart(2, "0")}
onChange={(e) => setHours(e.target.value)}
/>
</div>
<div>
<label htmlFor="minutes">Minutes</label>
<input
name="minutes"
type="number"
min="0"
max="59"
value={minutes.padStart(2, "0")}
onChange={(e) => setMinutes(e.target.value)}
/>
</div>
<div>
<label htmlFor="seconds">Seconds</label>
<input
name="seconds"
type="number"
min="0"
max="59"
value={seconds.padStart(2, "0")}
onChange={(e) => setSeconds(e.target.value)}
/>
</div>
</div>
);
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…