Skip to content
Discussion options

You must be logged in to vote
import { useState } from "react";
import Question from "./Question";
import { useForm, FormProvider } from "react-hook-form";
import * as yup from "yup";
import { yupResolver } from "@hookform/resolvers/yup";

export default function MultiStepForm() {
  const [step, setStep] = useState(0);

  const schema = [
    yup.object().shape({
      question_1: yup.string().required(),
    }),
    yup.object().shape({
      question_2: yup.string().required(),
    }),
    yup.object().shape({
      question_3: yup.string().required(),
    }),
  ];

  const currentSchema = schema[step];

  const methods = useForm({
    shouldUnregister: false,
    defaultValues: {
      question_1: "",
      questio…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jamesgordo
Comment options

Answer selected by jamesgordo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants