Secure OTP Verification UI
At Zepto, ensuring a seamless and secure user experience for critical actions like login, payment, or account recovery is paramount. OTP (One-Time Password) verification is a key part of this process. A well-designed OTP input component not only enhances security but also significantly improves user satisfaction by making the input process intuitive and error-free. This problem challenges you to build a robust and user-friendly OTP input component that handles various interaction patterns and states.
Your task is to create a reusable OtpInput React component with the following features:
length prop (e.g., 6 for a 6-digit OTP).length individual input fields for each digit.Backspace is pressed in an input field, it should clear the current field's digit and move focus to the previous input field. If already in the first field, it should only clear the digit.onChange prop that is called with the current OTP string whenever any digit changes.onComplete prop that is called with the full OTP string only when all length digits have been successfully entered.isError boolean prop. When true, the input fields should visually indicate an error state (e.g., red border).isLoading boolean prop. When true, all input fields should be disabled, and a visual loading indicator should be displayed.length distinct input fields.Backspace clears the current digit and moves focus to the previous input (unless it's the first).Left Arrow / Right Arrow moves focus to the adjacent input.onChange callback fires with the current OTP string after each digit entry/change.onComplete callback fires with the full OTP string only when all digits are entered.isLoading is true.isError is true.Constraints
length prop will be an integer between 4 and 8, inclusive.useState, useRef, useEffect).Loading editor...