Hard
In a complex form application, you need to programmatically focus inputs based on validation states. What's the correct way to implement the missing code to make this work?
1const Input = forwardRef((props, ref) => {2 const inputRef = useRef(null);3 const [error, setError] = useState(null);45 // Missing implementation6 ____________________7 ____________________8 ____________________910 return (11 <div className="input-wrapper">12 <input13 {...props}14 ref={inputRef}15 className={error ? 'error' : ''}16 />17 {error && <span className="error-message">{error}</span>}18 </div>19 );20});2122function Form() {23 const firstNameRef = useRef(null);24 const lastNameRef = useRef(null);2526 const handleSubmit = (e) => {27 e.preventDefault();28 if (!firstNameRef.current.value) {29 firstNameRef.current.focus();30 firstNameRef.current.setError('Required field');31 }32 };3334 return (35 <form onSubmit={handleSubmit}>36 <Input ref={firstNameRef} name="firstName" />37 <Input ref={lastNameRef} name="lastName" />38 </form>39 );40}