How to use @hookform/resolvers - 6 common examples

To help you get started, we’ve selected a few @hookform/resolvers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lyft / clutch / frontend / packages / core / src / Table / metadata-table.tsx View on Github external
} else {
    rows = data.map(row => {
      const id = row?.input?.key || _.camelCase(row.name);
      return { ...row, id };
    });
  }

  const validationShape = {};
  rows.forEach(row => {
    if (row?.input?.validation) {
      validationShape[row.name] = row.input.validation;
    }
  });
  const validation = useForm({
    mode: "onChange",
    resolver: yupResolver(object().shape(validationShape)),
  });
  const { control, handleSubmit } = validation;

  React.useEffect(() => {
    setOnSubmit(handleSubmit);
  }, []);

  return (
    
      {process.env.REACT_APP_DEBUG_FORMS && onUpdate !== undefined && }
      
          {rows.map((row: IdentifiableRowData) => {
            return row.input !== undefined && onUpdate ? (
              <table>
        </table>
github lyft / clutch / frontend / workflows / serverexperimentation / src / start-experiment.tsx View on Github external
},
  ] as FormItem[];

  const schema: { [name: string]: yup.StringSchema | yup.NumberSchema } = {};
  const visibleFields = fields.filter(field =&gt; field.visible !== false);
  visibleFields
    .filter(field =&gt; field.validation !== undefined)
    .reduce((accumulator, field) =&gt; {
      accumulator[field.name] = field.validation;
      return accumulator;
    }, schema);

  const { register, errors, handleSubmit } = useForm({
    mode: "onChange",
    reValidateMode: "onChange",
    resolver: yupResolver(yup.object().shape(schema)),
  });

  return (
    <form>
      
      
        <button>
        </button><button type="submit">
      
    
  );</button></form>
github lyft / clutch / frontend / workflows / serverexperimentation / src / start-experiment.tsx View on Github external
},
  ] as FormItem[];

  const schema: { [name: string]: yup.StringSchema | yup.NumberSchema } = {};
  const visibleFields = fields.filter(field =&gt; field.visible !== false);
  visibleFields
    .filter(field =&gt; field.validation !== undefined)
    .reduce((accumulator, field) =&gt; {
      accumulator[field.name] = field.validation;
      return accumulator;
    }, schema);

  const { register, errors, handleSubmit } = useForm({
    mode: "onChange",
    reValidateMode: "onChange",
    resolver: yupResolver(yup.object().shape(schema)),
  });

  return (
    <form>
      
      
        <button>
        </button><button type="submit">
      
    
  );</button></form>
github lyft / clutch / frontend / workflows / sourcecontrol / src / create-repository.tsx View on Github external
const RepositoryDetails: React.FC = () =&gt; {
  const { register, errors, handleSubmit } = useForm({
    mode: "onChange",
    reValidateMode: "onChange",
    resolver: yupResolver(schema),
  });
  const { onSubmit } = useWizardContext();
  const repositoryData = useDataLayout("repositoryData");
  const repositoryOptions = repositoryData.displayValue()
    .data as IClutch.sourcecontrol.v1.GetRepositoryOptionsResponse;

  return (
    
      <form>
        <select name="owner" label="Owner"> repositoryData.updateData("owner", value)}
          options={repositoryOptions?.availableOwners?.map(owner =&gt; {
            return { label: owner.name, startAdornment:  };
          })}</select></form>
github TheOdinProject / theodinproject / app / javascript / components / project-submissions / components / edit-form.jsx View on Github external
const EditForm = ({
  submission, onSubmit, onClose, onDelete,
}) =&gt; {
  const {
    register, errors, handleSubmit, formState,
  } = useForm({
    resolver: yupResolver(schema),
    defaultValues: {
      repo_url: submission.repo_url,
      live_preview_url: submission.live_preview_url,
      is_public: submission.is_public,
    },
  });

  const handleDelete = () =&gt; {
    onDelete(submission.id);
    onClose();
  };

  if (formState.isSubmitSuccessful) {
    return (
      <div>
        <h1>Thanks for Updating Your Solution!</h1></div>
github TheOdinProject / theodinproject / app / javascript / components / project-submissions / components / create-form.jsx View on Github external
const CreateForm = ({ onClose, onSubmit, userId }) =&gt; {
  const { lesson } = useContext(ProjectSubmissionContext);
  const {
    register, handleSubmit, formState, errors,
  } = useForm({
    resolver: yupResolver(schema),
    defaultValues: {
      is_public: true,
    },
  });

  if (userId === null) {
    return (
      <div>
        <h1>Please Sign in</h1>
        <p data-test-id="sign-in-instructions">
          Please
          {' '}
          <a href="/login">sign in</a>
          {' '}
          to add a project submission.
        </p></div>

@hookform/resolvers

React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types, TypeBox, arktype, Typanion, Effect-TS and VineJS

MIT
Latest version published 24 days ago

Package Health Score

95 / 100
Full package analysis