You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{useForm}from'react-hook-form';import{ajvResolver}from'@hookform/resolvers/ajv';// must use `minLength: 1` to implement required fieldconstschema={type: 'object',properties: {username: {type: 'string',minLength: 1,errorMessage: {minLength: 'username field is required'},},password: {type: 'string',minLength: 1,errorMessage: {minLength: 'password field is required'},},},required: ['username','password'],additionalProperties: false,};constApp=()=>{const{
register,
handleSubmit,formState: { errors },}=useForm({resolver: ajvResolver(schema),});return(<formonSubmit={handleSubmit((data)=>console.log(data))}><input{...register('username')}/>{errors.username&&<span>{errors.username.message}</span>}<input{...register('password')}/>{errors.password&&<span>{errors.password.message}</span>}<buttontype="submit">submit</button></form>);};