8.0.8 • Published 2 months ago

@graphcommerce/react-hook-form v8.0.8

Weekly downloads
-
License
-
Repository
github
Last release
2 months ago

Form

The Form component is an extension of the (React Hook Form)(https://react-hook-form.com/) package which adds new hooks.

useFormGqlMutation

Simple example:

import { useFormGqlMutation } from '@graphcommerce/react-hook-form'

const mutation = gql`
  mutation ApplyCouponToCart($cartId: String!, $couponCode: String!) {
    applyCouponToCart(input: { cart_id: $cartId, coupon_code: $couponCode }) {
      cart {
        id
      }
    }
  }
`

export default function MyComponent() {
  const form = useFormGqlMutation(mutation, {
    defaultValues: { cartId: cartQuery?.cart?.id },
  })
  const { errors, handleSubmit, register, formState, required, error } = form

  // We don't need to provide an actual handler as useFormGqlMutation already adds that.
  const submit = handleSubmit(() => {})

  return (
    <form onSubmit={submit} noValidate>
      <input
        type='text'
        {...register('couponCode', { required: required.couponCode })}
        disabled={formState.isSubmitting}
      />
      {errors.couponCode?.message || error?.message}
      <button type='submit'>submit</button>
    </form>
  )
}

useFormGqlQuery

import { useFormGqlQuery } from '@graphcommerce/react-hook-form'

const query = gql`
  query IsEmailAvailable($email: String!) {
    isEmailAvailable(email: $email) {
      is_email_available
    }
  }
`

export default function MyComponent() {
  const form = useFormGqlQuery(query, {})
  const { errors, handleSubmit, register, formState, required, error } = form

  // We don't need to provide an actual handler as useFormGqlQuery already adds that.
  const submit = handleSubmit(() => {})

  return (
    <form onSubmit={submit} noValidate>
      <input
        type='text'
        {...register('couponCode', { required: required.couponCode })}
        disabled={formState.isSubmitting}
      />
      {errors.couponCode?.message || error?.message}
      <button type='submit'>submit</button>
    </form>
  )
}

useFormAutoSubmit

import { useFormAutoSubmit } from '@graphcommerce/react-hook-form'

export default function MyAutoSubmitForm() {
  // Regular useForm hook, but you can also use useFormGqlMutation
  const form = useForm()
  const { errors, handleSubmit, register, formState, required } = form

  const submit = handleSubmit(() => {
    console.log('submitted')
  })
  const autoSubmitting = useFormAutoSubmit({
    form,
    submit,
    fields: ['couponCode'], //optional, default: all fields
    wait: 1200, // optional, default: 500ms
  })
  const disableFields = formState.isSubmitting && !autoSubmitting

  return (
    <form onSubmit={submit} noValidate>
      <input
        type='text'
        {...register('couponCode', { required: required.couponCode })}
        disabled={formState.isSubmitting}
      />
      {errors.couponCode?.message}
    </form>
  )
}

useFormPersist

import { useFormAutoSubmit } from '@graphcommerce/react-hook-form'

export default function MyAutoSubmitForm() {
  // Regular useForm hook, but you can also use useFormGqlMutation
  const form = useForm()
  const { errors, handleSubmit, register, formState, required } = form

  const submit = handleSubmit(() => {
    console.log('submitted')
  })
  const autoSubmitting = useFormPersist({ form, name: 'MyForm' })
  const disableFields = formState.isSubmitting && !autoSubmitting

  return (
    <form onSubmit={submit} noValidate>
      <input
        type='text'
        {...register('couponCode', { required: required.couponCode })}
        disabled={disableFields}
      />
      {errors.couponCode?.message}
    </form>
  )
}

FAQ

Why is my useForm hook not submitting anything?

const form = useForm() // INCORRECT

const form useForm({ // CORRECT
  mode: 'onSubmit',
  defaultValues: {
   yourFieldName: 'default value',
  },
})
9.0.0-canary.94

2 months ago

9.0.0-canary.89

2 months ago

9.0.0-canary.88

2 months ago

9.0.0-canary.92

2 months ago

9.0.0-canary.93

2 months ago

9.0.0-canary.87

2 months ago

8.0.8

2 months ago

9.0.0-canary.83

3 months ago

9.0.0-canary.85

3 months ago

9.0.0-canary.84

3 months ago

9.0.0-canary.86

3 months ago

9.0.0-canary.81

3 months ago

9.0.0-canary.82

3 months ago

9.0.0-canary.69

5 months ago

9.0.0-canary.68

5 months ago

9.0.0-canary.61

5 months ago

9.0.0-canary.60

5 months ago

9.0.0-canary.63

5 months ago

9.0.0-canary.62

5 months ago

9.0.0-canary.65

5 months ago

9.0.0-canary.64

5 months ago

9.0.0-canary.67

5 months ago

9.0.0-canary.66

5 months ago

9.0.0-canary.70

5 months ago

9.0.0-canary.79

4 months ago

9.0.0-canary.72

5 months ago

9.0.0-canary.71

5 months ago

9.0.0-canary.74

4 months ago

9.0.0-canary.73

4 months ago

9.0.0-canary.76

4 months ago

9.0.0-canary.75

4 months ago

9.0.0-canary.78

4 months ago

9.0.0-canary.77

4 months ago

9.0.0-canary.80

4 months ago

9.0.0-canary.58

5 months ago

9.0.0-canary.57

5 months ago

9.0.0-canary.59

5 months ago

9.0.0-canary.54

5 months ago

9.0.0-canary.56

5 months ago

9.0.0-canary.55

5 months ago

8.1.0-canary.30

6 months ago

8.1.0-canary.32

6 months ago

8.1.0-canary.31

6 months ago

8.1.0-canary.34

6 months ago

8.1.0-canary.33

6 months ago

8.1.0-canary.36

6 months ago

8.1.0-canary.35

6 months ago

8.1.0-canary.38

6 months ago

8.1.0-canary.37

6 months ago

8.1.0-canary.39

6 months ago

8.1.0-canary.20

7 months ago

8.1.0-canary.23

7 months ago

8.1.0-canary.22

7 months ago

8.1.0-canary.25

7 months ago

8.1.0-canary.24

7 months ago

8.1.0-canary.27

7 months ago

8.1.0-canary.26

7 months ago

8.1.0-canary.29

6 months ago

8.1.0-canary.28

6 months ago

8.1.0-canary.50

5 months ago

8.1.0-canary.52

5 months ago

8.1.0-canary.53

5 months ago

8.1.0-canary.41

6 months ago

8.1.0-canary.40

6 months ago

8.1.0-canary.43

6 months ago

8.1.0-canary.42

6 months ago

8.1.0-canary.45

6 months ago

8.1.0-canary.44

6 months ago

8.1.0-canary.47

6 months ago

8.1.0-canary.46

6 months ago

8.1.0-canary.49

5 months ago

8.1.0-canary.48

5 months ago

8.0.7

5 months ago

8.1.0-canary.16

7 months ago

8.1.0-canary.18

7 months ago

8.1.0-canary.17

7 months ago

8.1.0-canary.19

7 months ago

8.0.6

7 months ago

8.1.0-canary.14

7 months ago

8.1.0-canary.13

7 months ago

8.1.0-canary.15

7 months ago

8.1.0-canary.12

8 months ago

8.1.0-canary.11

8 months ago

8.1.0-canary.9

8 months ago

8.1.0-canary.10

8 months ago

8.1.0-canary.8

8 months ago

8.1.0-canary.6

8 months ago

8.1.0-canary.7

8 months ago

8.0.5-canary.11

8 months ago

8.1.0-canary.5

8 months ago

8.0.6-canary.0

8 months ago

8.0.6-canary.2

8 months ago

8.0.6-canary.1

8 months ago

8.0.6-canary.4

8 months ago

8.0.6-canary.3

8 months ago

8.0.5-canary.9

8 months ago

8.0.5-canary.10

8 months ago

8.0.5

8 months ago

8.0.5-canary.8

8 months ago

8.0.5-canary.7

8 months ago

8.0.5-canary.6

8 months ago

8.0.5-canary.5

9 months ago

8.0.5-canary.4

9 months ago

8.0.5-canary.3

9 months ago

8.0.5-canary.2

9 months ago

8.0.5-canary.1

9 months ago

8.0.5-canary.0

9 months ago

8.0.4-canary.1

9 months ago

8.0.4

9 months ago

8.0.3-canary.9

9 months ago

8.0.4-canary.0

9 months ago

8.0.3-canary.8

9 months ago

8.0.3-canary.7

9 months ago

8.0.3

10 months ago

8.0.3-canary.6

10 months ago

8.0.3-canary.5

10 months ago

8.0.3-canary.4

10 months ago

8.0.3-canary.2

10 months ago

8.0.3-canary.3

10 months ago

8.1.0-canary.2

10 months ago

8.1.0-canary.3

10 months ago

8.0.3-canary.0

10 months ago

8.0.3-canary.1

10 months ago

8.0.2-canary.3

10 months ago

8.0.2-canary.2

10 months ago

8.0.2-canary.0

10 months ago

8.0.2

10 months ago

8.0.1-canary.4

11 months ago

8.0.1

11 months ago

8.0.1-canary.3

11 months ago

8.0.1-canary.2

11 months ago

8.0.1-canary.1

11 months ago

8.0.1-canary.0

11 months ago

8.0.0-canary.100

11 months ago

8.0.0-canary.98

11 months ago

8.0.0-canary.99

11 months ago

8.0.0-canary.97

11 months ago

8.0.0

11 months ago

8.0.0-canary.94

11 months ago

8.0.0-canary.95

11 months ago

8.0.0-canary.93

11 months ago

8.0.0-canary.92

11 months ago

8.0.0-canary.91

11 months ago

8.0.0-canary.89

11 months ago

8.0.0-canary.90

11 months ago

8.0.0-canary.78

11 months ago

8.0.0-canary.79

11 months ago

8.0.0-canary.80

11 months ago

8.0.0-canary.81

11 months ago

8.0.0-canary.82

11 months ago

8.0.0-canary.87

11 months ago

8.0.0-canary.88

11 months ago

8.0.0-canary.83

11 months ago

8.0.0-canary.84

11 months ago

8.0.0-canary.85

11 months ago

8.0.0-canary.86

11 months ago

8.0.0-canary.76

12 months ago

8.0.0-canary.77

12 months ago

8.0.0-canary.75

12 months ago

8.0.0-canary.73

12 months ago

8.0.0-canary.74

12 months ago

8.0.0-canary.72

12 months ago

8.0.0-canary.69

12 months ago

8.0.0-canary.70

12 months ago

8.0.0-canary.71

12 months ago

7.1.0-canary.68

12 months ago

7.1.0-canary.66

12 months ago

7.1.0-canary.67

12 months ago

7.1.0-canary.65

1 year ago

7.1.0-canary.64

1 year ago

7.1.0-canary.63

1 year ago

7.0.2-canary.7

1 year ago

7.0.2-canary.6

1 year ago

7.0.2-canary.3

1 year ago

7.0.2-canary.2

1 year ago

7.0.2-canary.5

1 year ago

7.0.2-canary.4

1 year ago

7.0.2-canary.1

1 year ago

7.0.2-canary.0

1 year ago

6.2.0-canary.60

1 year ago

6.2.0-canary.57

1 year ago

6.2.0-canary.59

1 year ago

6.2.0-canary.58

1 year ago

8.0.0-canary.40

1 year ago

7.1.0-canary.9

1 year ago

7.1.0-canary.8

1 year ago

7.1.0-canary.36

1 year ago

7.1.0-canary.37

1 year ago

7.1.0-canary.38

1 year ago

7.1.0-canary.39

1 year ago

7.1.0-canary.32

1 year ago

7.1.0-canary.33

1 year ago

7.1.0-canary.34

1 year ago

7.1.0-canary.35

1 year ago

7.1.0-canary.30

1 year ago

7.1.0-canary.31

1 year ago

7.1.0-canary.29

1 year ago

7.1.0-canary.25

1 year ago

7.1.0-canary.26

1 year ago

7.1.0-canary.27

1 year ago

7.1.0-canary.28

1 year ago

7.1.0-canary.21

1 year ago

7.1.0-canary.22

1 year ago

7.1.0-canary.23

1 year ago

7.1.0-canary.24

1 year ago

7.1.0-canary.20

1 year ago

7.1.0-canary.18

1 year ago

7.1.0-canary.19

1 year ago

7.1.0-canary.14

1 year ago

7.1.0-canary.15

1 year ago

7.1.0-canary.16

1 year ago

7.1.0-canary.17

1 year ago

7.1.0-canary.10

1 year ago

7.0.0

1 year ago

7.1.0-canary.11

1 year ago

7.1.0-canary.12

1 year ago

7.1.0-canary.13

1 year ago

7.0.1

1 year ago

7.0.1-canary.15

1 year ago

7.0.1-canary.14

1 year ago

7.0.1-canary.13

1 year ago

7.0.1-canary.12

1 year ago

7.0.1-canary.11

1 year ago

7.0.1-canary.10

1 year ago

6.2.0-canary.91

1 year ago

6.2.0-canary.90

1 year ago

6.2.0-canary.93

1 year ago

6.2.0-canary.92

1 year ago

6.2.0-canary.88

1 year ago

6.2.0-canary.87

1 year ago

6.2.0-canary.89

1 year ago

6.2.0-canary.84

1 year ago

6.2.0-canary.83

1 year ago

6.2.0-canary.86

1 year ago

6.2.0-canary.85

1 year ago

6.2.0-canary.98

1 year ago

6.2.0-canary.95

1 year ago

6.2.0-canary.94

1 year ago

6.2.0-canary.97

1 year ago

6.2.0-canary.96

1 year ago

7.1.0-canary.61

1 year ago

7.1.0-canary.62

1 year ago

7.1.0-canary.60

1 year ago

6.2.0-canary.71

1 year ago

6.2.0-canary.70

1 year ago

6.2.0-canary.66

1 year ago

6.2.0-canary.65

1 year ago

6.2.0-canary.68

1 year ago

6.2.0-canary.67

1 year ago

7.1.0-canary.58

1 year ago

6.2.0-canary.62

1 year ago

7.1.0-canary.59

1 year ago

6.2.0-canary.61

1 year ago

6.2.0-canary.64

1 year ago

6.2.0-canary.63

1 year ago

7.1.0-canary.54

1 year ago

7.1.0-canary.55

1 year ago

7.1.0-canary.56

1 year ago

7.1.0-canary.57

1 year ago

7.1.0-canary.50

1 year ago

7.1.0-canary.51

1 year ago

6.2.0-canary.69

1 year ago

7.1.0-canary.52

1 year ago

7.1.0-canary.53

1 year ago

6.2.0-canary.80

1 year ago

7.0.1-canary.9

1 year ago

6.2.0-canary.82

1 year ago

6.2.0-canary.81

1 year ago

7.0.1-canary.7

1 year ago

7.0.1-canary.8

1 year ago

7.0.1-canary.5

1 year ago

7.0.1-canary.6

1 year ago

7.0.1-canary.3

1 year ago

6.2.0-canary.77

1 year ago

7.0.1-canary.4

1 year ago

6.2.0-canary.76

1 year ago

7.0.1-canary.1

1 year ago

6.2.0-canary.79

1 year ago

7.0.1-canary.2

1 year ago

6.2.0-canary.78

1 year ago

7.1.0-canary.47

1 year ago

6.2.0-canary.73

1 year ago

7.1.0-canary.48

1 year ago

7.0.1-canary.0

1 year ago

6.2.0-canary.72

1 year ago

7.1.0-canary.49

1 year ago

6.2.0-canary.75

1 year ago

6.2.0-canary.74

1 year ago

7.1.0-canary.43

1 year ago

7.1.0-canary.44

1 year ago

7.1.0-canary.45

1 year ago

7.1.0-canary.46

1 year ago

7.1.0-canary.41

1 year ago

7.1.0-canary.42

1 year ago

6.2.0-canary.56

1 year ago

6.2.0-canary.44

2 years ago

6.2.0-canary.43

2 years ago

6.2.0-canary.46

2 years ago

6.2.0-canary.45

2 years ago

6.2.0-canary.40

2 years ago

6.2.0-canary.42

2 years ago

6.2.0-canary.41

2 years ago

6.2.0-canary.48

2 years ago

6.2.0-canary.47

2 years ago

6.2.0-canary.49

2 years ago

6.2.0-canary.55

1 year ago

6.2.0-canary.54

1 year ago

6.2.0-canary.51

2 years ago

6.2.0-canary.50

2 years ago

6.2.0-canary.53

1 year ago

6.2.0-canary.52

1 year ago

6.2.0-canary.35

2 years ago

6.2.0-canary.34

2 years ago

6.2.0-canary.37

2 years ago

6.2.0-canary.36

2 years ago

6.2.0-canary.39

2 years ago

6.2.0-canary.38

2 years ago

7.0.0-canary.21

2 years ago

6.2.0-canary.22

2 years ago

6.2.0-canary.21

2 years ago

6.2.0-canary.24

2 years ago

6.2.0-canary.23

2 years ago

6.2.0-canary.20

2 years ago

6.2.0-canary.29

2 years ago

7.0.0-canary.13

2 years ago

7.0.0-canary.12

2 years ago

6.2.0-canary.26

2 years ago

6.2.0-canary.25

2 years ago

6.2.0-canary.28

2 years ago

6.2.0-canary.27

2 years ago

6.2.0-canary.33

2 years ago

6.2.0-canary.32

2 years ago

6.2.0-canary.31

2 years ago

6.2.0-canary.30

2 years ago

6.2.0-canary.11

2 years ago

6.2.0-canary.10

2 years ago

6.2.0-canary.13

2 years ago

6.2.0-canary.12

2 years ago

6.2.0-canary.19

2 years ago

6.2.0-canary.18

2 years ago

6.2.0-canary.15

2 years ago

6.2.0-canary.14

2 years ago

6.2.0-canary.17

2 years ago

6.2.0-canary.16

2 years ago

6.2.0-canary.7

2 years ago

6.2.0-canary.8

2 years ago

6.2.0-canary.6

2 years ago

6.2.0-canary.9

2 years ago

6.1.1-canary.3

2 years ago

6.1.1-canary.4

2 years ago

6.1.1-canary.5

2 years ago

6.0.0-canary.51

2 years ago

6.0.0-canary.50

2 years ago

6.1.0

2 years ago

6.0.0-canary.49

2 years ago

6.0.2-canary.22

2 years ago

6.0.2-canary.21

2 years ago

6.0.0-canary.44

2 years ago

6.0.0-canary.43

2 years ago

6.0.0-canary.42

2 years ago

6.0.0-canary.41

2 years ago

6.0.0-canary.48

2 years ago

6.0.0-canary.47

2 years ago

6.0.0-canary.46

2 years ago

6.0.0-canary.45

2 years ago

6.0.1-canary.4

2 years ago

6.0.1-canary.5

2 years ago

6.0.1-canary.6

2 years ago

6.0.1-canary.7

2 years ago

6.0.1-canary.0

2 years ago

6.0.1-canary.1

2 years ago

6.0.1-canary.2

2 years ago

6.0.1-canary.3

2 years ago

6.0.0-canary.54

2 years ago

6.0.0-canary.53

2 years ago

6.0.0-canary.52

2 years ago

6.0.0-canary.40

2 years ago

6.0.0-canary.39

2 years ago

6.0.0-canary.38

2 years ago

6.0.0-canary.33

2 years ago

6.0.0-canary.32

2 years ago

6.0.0-canary.37

2 years ago

6.0.0-canary.36

2 years ago

6.0.0-canary.35

2 years ago

6.0.0-canary.34

2 years ago

6.0.2-canary.8

2 years ago

6.0.2-canary.7

2 years ago

6.0.2-canary.6

2 years ago

6.0.2-canary.5

2 years ago

6.0.2-canary.9

2 years ago

6.0.2-canary.0

2 years ago

6.0.2-canary.4

2 years ago

6.0.2-canary.3

2 years ago

6.0.2-canary.2

2 years ago

6.0.2-canary.1

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.1.1-canary.0

2 years ago

6.1.1-canary.1

2 years ago

6.1.1-canary.2

2 years ago

6.0.2-canary.10

2 years ago

6.0.2-canary.13

2 years ago

6.0.2-canary.12

2 years ago

6.0.2-canary.15

2 years ago

6.0.2-canary.14

2 years ago

6.0.2-canary.17

2 years ago

6.0.2-canary.16

2 years ago

6.0.2-canary.19

2 years ago

6.0.2-canary.18

2 years ago

6.0.0-canary.29

2 years ago

6.0.0-canary.28

2 years ago

6.0.0-canary.27

2 years ago

6.0.0-canary.31

2 years ago

6.0.0-canary.30

2 years ago

6.0.0-canary.26

2 years ago

6.0.0-canary.25

2 years ago

6.0.0-canary.22

2 years ago

6.0.0-canary.21

2 years ago

6.0.0-canary.20

2 years ago

6.0.0-canary.24

2 years ago

6.0.0-canary.23

2 years ago

5.2.0-canary.13

2 years ago

5.2.0-canary.14

2 years ago

5.2.0-canary.15

2 years ago

5.2.0-canary.16

2 years ago

5.2.0-canary.17

2 years ago

5.2.0-canary.18

2 years ago

5.2.0-canary.19

2 years ago

5.2.0-canary.10

2 years ago

5.2.0-canary.11

2 years ago

5.2.0-canary.12

2 years ago

5.2.0-canary.7

2 years ago

5.2.0-canary.8

2 years ago

5.2.0-canary.9

2 years ago

5.1.1

2 years ago

5.1.0

2 years ago

5.1.0-canary.11

2 years ago

5.1.0-canary.10

2 years ago

5.0.0-canary.14

2 years ago

5.1.1-canary.0

2 years ago

5.1.1-canary.1

2 years ago

4.31.0-canary.0

2 years ago

4.31.0-canary.2

2 years ago

4.31.0-canary.1

2 years ago

4.31.0-canary.4

2 years ago

4.31.0-canary.3

2 years ago

4.31.0-canary.6

2 years ago

4.31.0-canary.5

2 years ago

5.0.0-canary.9

2 years ago

4.31.0-canary.8

2 years ago

4.31.0-canary.7

2 years ago

5.1.0-canary.5

2 years ago

5.1.0-canary.6

2 years ago

5.1.0-canary.3

2 years ago

5.1.0-canary.4

2 years ago

5.1.0-canary.9

2 years ago

5.1.0-canary.7

2 years ago

5.0.0

2 years ago

5.1.0-canary.8

2 years ago

5.2.0-canary.0

2 years ago

5.2.0-canary.1

2 years ago

5.2.0-canary.2

2 years ago

5.2.0-canary.3

2 years ago

5.2.0-canary.4

2 years ago

5.2.0-canary.5

2 years ago

5.2.0-canary.6

2 years ago

5.1.0-canary.1

2 years ago

5.1.0-canary.2

2 years ago

5.1.0-canary.0

2 years ago

4.30.2

2 years ago

4.30.1

2 years ago

3.3.5

2 years ago

3.3.4

2 years ago

4.30.0

2 years ago

4.30.0-canary.1

2 years ago

4.30.0-canary.0

2 years ago

3.3.3

2 years ago

3.3.1

2 years ago

3.2.2

3 years ago

3.3.0

2 years ago

3.3.2

2 years ago

3.1.3

3 years ago

3.2.1

3 years ago

3.1.2

3 years ago

3.2.0

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.7

3 years ago

3.0.6

3 years ago

3.0.5

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.104.7

3 years ago

2.104.6

3 years ago

2.104.5

3 years ago

2.104.4

3 years ago

2.104.3

3 years ago

2.104.2

3 years ago

2.104.1

3 years ago

2.104.0

3 years ago

2.103.1

3 years ago

2.103.0

3 years ago

2.102.14

3 years ago

2.102.13

3 years ago

2.102.12

3 years ago

2.102.11

3 years ago

2.102.10

3 years ago

2.102.9

3 years ago

2.102.8

3 years ago

2.102.7

3 years ago

2.102.6

3 years ago

2.102.5

3 years ago

2.102.4

3 years ago

2.102.3

3 years ago

2.102.2

3 years ago

2.102.1

3 years ago