8.0.8 • Published 22 days ago

@graphcommerce/react-hook-form v8.0.8

Weekly downloads
-
License
-
Repository
github
Last release
22 days 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

22 days ago

9.0.0-canary.89

26 days ago

9.0.0-canary.88

26 days ago

9.0.0-canary.92

26 days ago

9.0.0-canary.93

24 days ago

9.0.0-canary.87

1 month ago

8.0.8

1 month ago

9.0.0-canary.83

2 months ago

9.0.0-canary.85

2 months ago

9.0.0-canary.84

2 months ago

9.0.0-canary.86

2 months ago

9.0.0-canary.81

2 months ago

9.0.0-canary.82

2 months ago

9.0.0-canary.69

4 months ago

9.0.0-canary.68

4 months ago

9.0.0-canary.61

4 months ago

9.0.0-canary.60

4 months ago

9.0.0-canary.63

4 months ago

9.0.0-canary.62

4 months ago

9.0.0-canary.65

4 months ago

9.0.0-canary.64

4 months ago

9.0.0-canary.67

4 months ago

9.0.0-canary.66

4 months ago

9.0.0-canary.70

4 months ago

9.0.0-canary.79

3 months ago

9.0.0-canary.72

4 months ago

9.0.0-canary.71

4 months ago

9.0.0-canary.74

3 months ago

9.0.0-canary.73

3 months ago

9.0.0-canary.76

3 months ago

9.0.0-canary.75

3 months ago

9.0.0-canary.78

3 months ago

9.0.0-canary.77

3 months ago

9.0.0-canary.80

3 months ago

9.0.0-canary.58

4 months ago

9.0.0-canary.57

4 months ago

9.0.0-canary.59

4 months ago

9.0.0-canary.54

4 months ago

9.0.0-canary.56

4 months ago

9.0.0-canary.55

4 months ago

8.1.0-canary.30

5 months ago

8.1.0-canary.32

5 months ago

8.1.0-canary.31

5 months ago

8.1.0-canary.34

5 months ago

8.1.0-canary.33

5 months ago

8.1.0-canary.36

5 months ago

8.1.0-canary.35

5 months ago

8.1.0-canary.38

5 months ago

8.1.0-canary.37

5 months ago

8.1.0-canary.39

5 months ago

8.1.0-canary.20

6 months ago

8.1.0-canary.23

6 months ago

8.1.0-canary.22

6 months ago

8.1.0-canary.25

6 months ago

8.1.0-canary.24

6 months ago

8.1.0-canary.27

6 months ago

8.1.0-canary.26

6 months ago

8.1.0-canary.29

5 months ago

8.1.0-canary.28

5 months ago

8.1.0-canary.50

4 months ago

8.1.0-canary.52

4 months ago

8.1.0-canary.53

4 months ago

8.1.0-canary.41

5 months ago

8.1.0-canary.40

5 months ago

8.1.0-canary.43

5 months ago

8.1.0-canary.42

5 months ago

8.1.0-canary.45

5 months ago

8.1.0-canary.44

5 months ago

8.1.0-canary.47

5 months ago

8.1.0-canary.46

5 months ago

8.1.0-canary.49

4 months ago

8.1.0-canary.48

4 months ago

8.0.7

4 months ago

8.1.0-canary.16

6 months ago

8.1.0-canary.18

6 months ago

8.1.0-canary.17

6 months ago

8.1.0-canary.19

6 months ago

8.0.6

6 months ago

8.1.0-canary.14

6 months ago

8.1.0-canary.13

6 months ago

8.1.0-canary.15

6 months ago

8.1.0-canary.12

7 months ago

8.1.0-canary.11

7 months ago

8.1.0-canary.9

7 months ago

8.1.0-canary.10

7 months ago

8.1.0-canary.8

7 months ago

8.1.0-canary.6

7 months ago

8.1.0-canary.7

7 months ago

8.0.5-canary.11

7 months ago

8.1.0-canary.5

7 months ago

8.0.6-canary.0

7 months ago

8.0.6-canary.2

7 months ago

8.0.6-canary.1

7 months ago

8.0.6-canary.4

7 months ago

8.0.6-canary.3

7 months ago

8.0.5-canary.9

7 months ago

8.0.5-canary.10

7 months ago

8.0.5

7 months ago

8.0.5-canary.8

7 months ago

8.0.5-canary.7

7 months ago

8.0.5-canary.6

7 months ago

8.0.5-canary.5

7 months ago

8.0.5-canary.4

8 months ago

8.0.5-canary.3

8 months ago

8.0.5-canary.2

8 months ago

8.0.5-canary.1

8 months ago

8.0.5-canary.0

8 months ago

8.0.4-canary.1

8 months ago

8.0.4

8 months ago

8.0.3-canary.9

8 months ago

8.0.4-canary.0

8 months ago

8.0.3-canary.8

8 months ago

8.0.3-canary.7

8 months ago

8.0.3

9 months ago

8.0.3-canary.6

9 months ago

8.0.3-canary.5

9 months ago

8.0.3-canary.4

9 months ago

8.0.3-canary.2

9 months ago

8.0.3-canary.3

9 months ago

8.1.0-canary.2

9 months ago

8.1.0-canary.3

9 months ago

8.0.3-canary.0

9 months ago

8.0.3-canary.1

9 months ago

8.0.2-canary.3

9 months ago

8.0.2-canary.2

9 months ago

8.0.2-canary.0

9 months ago

8.0.2

9 months ago

8.0.1-canary.4

10 months ago

8.0.1

10 months ago

8.0.1-canary.3

10 months ago

8.0.1-canary.2

10 months ago

8.0.1-canary.1

10 months ago

8.0.1-canary.0

10 months ago

8.0.0-canary.100

10 months ago

8.0.0-canary.98

10 months ago

8.0.0-canary.99

10 months ago

8.0.0-canary.97

10 months ago

8.0.0

10 months ago

8.0.0-canary.94

10 months ago

8.0.0-canary.95

10 months ago

8.0.0-canary.93

10 months ago

8.0.0-canary.92

10 months ago

8.0.0-canary.91

10 months ago

8.0.0-canary.89

10 months ago

8.0.0-canary.90

10 months ago

8.0.0-canary.78

10 months ago

8.0.0-canary.79

10 months ago

8.0.0-canary.80

10 months ago

8.0.0-canary.81

10 months ago

8.0.0-canary.82

10 months ago

8.0.0-canary.87

10 months ago

8.0.0-canary.88

10 months ago

8.0.0-canary.83

10 months ago

8.0.0-canary.84

10 months ago

8.0.0-canary.85

10 months ago

8.0.0-canary.86

10 months ago

8.0.0-canary.76

11 months ago

8.0.0-canary.77

11 months ago

8.0.0-canary.75

11 months ago

8.0.0-canary.73

11 months ago

8.0.0-canary.74

11 months ago

8.0.0-canary.72

11 months ago

8.0.0-canary.69

11 months ago

8.0.0-canary.70

11 months ago

8.0.0-canary.71

11 months ago

7.1.0-canary.68

11 months ago

7.1.0-canary.66

11 months ago

7.1.0-canary.67

11 months ago

7.1.0-canary.65

12 months ago

7.1.0-canary.64

12 months ago

7.1.0-canary.63

12 months 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

12 months ago

7.1.0-canary.62

12 months ago

7.1.0-canary.60

12 months 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

12 months ago

6.2.0-canary.62

1 year ago

7.1.0-canary.59

12 months 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

12 months ago

7.1.0-canary.55

12 months ago

7.1.0-canary.56

12 months ago

7.1.0-canary.57

12 months 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

1 year ago

6.2.0-canary.43

1 year ago

6.2.0-canary.46

1 year ago

6.2.0-canary.45

1 year ago

6.2.0-canary.40

1 year ago

6.2.0-canary.42

1 year ago

6.2.0-canary.41

1 year ago

6.2.0-canary.48

1 year ago

6.2.0-canary.47

1 year ago

6.2.0-canary.49

1 year ago

6.2.0-canary.55

1 year ago

6.2.0-canary.54

1 year ago

6.2.0-canary.51

1 year ago

6.2.0-canary.50

1 year ago

6.2.0-canary.53

1 year ago

6.2.0-canary.52

1 year ago

6.2.0-canary.35

1 year ago

6.2.0-canary.34

1 year ago

6.2.0-canary.37

1 year ago

6.2.0-canary.36

1 year ago

6.2.0-canary.39

1 year ago

6.2.0-canary.38

1 year 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

1 year ago

6.2.0-canary.23

2 years ago

6.2.0-canary.20

2 years ago

6.2.0-canary.29

1 year ago

7.0.0-canary.13

2 years ago

7.0.0-canary.12

2 years ago

6.2.0-canary.26

1 year ago

6.2.0-canary.25

1 year ago

6.2.0-canary.28

1 year ago

6.2.0-canary.27

1 year ago

6.2.0-canary.33

1 year ago

6.2.0-canary.32

1 year ago

6.2.0-canary.31

1 year ago

6.2.0-canary.30

1 year 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

2 years ago

3.3.0

2 years ago

3.3.2

2 years ago

3.1.3

3 years ago

3.2.1

2 years ago

3.1.2

3 years ago

3.2.0

2 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