OTP Input

어려움

6자리 OTP/PIN 입력 필드

#javascript#otp

라이브 데모

Code: ------

코드

OTPInput.tsx
const [otp, setOtp] = useState(['', '', '', '', '', '']);
const handleChange = (index, value) => {
  const newOtp = [...otp];
  newOtp[index] = value.slice(-1);
  setOtp(newOtp);
  if (value && index < 5) inputRefs.current[index + 1]?.focus();
};