@graphcommerce/react-hook-form 8.0.3-canary.2 → 8.0.3-canary.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 8.0.3-canary.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2206](https://github.com/graphcommerce-org/graphcommerce/pull/2206) [`855ab09`](https://github.com/graphcommerce-org/graphcommerce/commit/855ab097b9ea204a7c73c6550b7a5e9e2290f378) - Cleanup `<FormAutoSubmit/>` and remove internal hook.
8
+ ([@paales](https://github.com/paales))
9
+
3
10
  ## 8.0.3-canary.2
4
11
 
5
12
  ## 8.0.3-canary.1
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/react-hook-form",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "8.0.3-canary.2",
5
+ "version": "8.0.3-canary.3",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -16,9 +16,9 @@
16
16
  },
17
17
  "peerDependencies": {
18
18
  "@apollo/client": "^3",
19
- "@graphcommerce/eslint-config-pwa": "^8.0.3-canary.2",
20
- "@graphcommerce/prettier-config-pwa": "^8.0.3-canary.2",
21
- "@graphcommerce/typescript-config-pwa": "^8.0.3-canary.2",
19
+ "@graphcommerce/eslint-config-pwa": "^8.0.3-canary.3",
20
+ "@graphcommerce/prettier-config-pwa": "^8.0.3-canary.3",
21
+ "@graphcommerce/typescript-config-pwa": "^8.0.3-canary.3",
22
22
  "graphql": "^16.6.0",
23
23
  "react": "^18.2.0",
24
24
  "react-dom": "^18.2.0",
@@ -5,11 +5,11 @@ import { useMemoObject } from '@graphcommerce/next-ui/hooks/useMemoObject'
5
5
  import { debounce } from '@mui/material'
6
6
  import React, { useCallback, useEffect, useRef, useState } from 'react'
7
7
  import {
8
- Control,
9
8
  DeepPartialSkipArrayKey,
10
9
  FieldPath,
11
10
  FieldValues,
12
11
  UseFormReturn,
12
+ UseWatchProps,
13
13
  useFormState,
14
14
  useWatch,
15
15
  } from 'react-hook-form'
@@ -98,21 +98,8 @@ export function useFormAutoSubmit<
98
98
  return submitting
99
99
  }
100
100
 
101
- export type FormAutoSubmitProps<
102
- TFieldValues extends FieldValues = FieldValues,
103
- TFieldNames extends readonly FieldPath<TFieldValues>[] = readonly FieldPath<TFieldValues>[],
104
- > = {
105
- // eslint-disable-next-line react/no-unused-prop-types
106
- control: Control<TFieldValues>
101
+ export type FormAutoSubmitProps<TFieldValues extends FieldValues = FieldValues> = {
107
102
  /** Autosubmit only when these field names update */
108
- // eslint-disable-next-line react/no-unused-prop-types
109
- name?: readonly [...TFieldNames]
110
-
111
- // eslint-disable-next-line react/no-unused-prop-types
112
- disabled?: boolean
113
-
114
- // eslint-disable-next-line react/no-unused-prop-types
115
- exact?: boolean
116
103
 
117
104
  /** SubmitHandler */
118
105
  // eslint-disable-next-line react/no-unused-prop-types
@@ -124,12 +111,15 @@ export type FormAutoSubmitProps<
124
111
  */
125
112
  // eslint-disable-next-line react/no-unused-prop-types
126
113
  parallel?: boolean
127
- } & DebounceOptions
114
+ } & DebounceOptions &
115
+ Omit<UseWatchProps<TFieldValues>, 'defaultValue'>
128
116
 
129
- function useFormAutoSubmit2<
130
- TFieldValues extends FieldValues = FieldValues,
131
- TFieldNames extends readonly FieldPath<TFieldValues>[] = readonly FieldPath<TFieldValues>[],
132
- >(props: FormAutoSubmitProps<TFieldValues, TFieldNames>) {
117
+ /**
118
+ * This is made a components so the useWatch that is used here doesn't retrigger the rerender of the parent component.
119
+ */
120
+ function FormAutoSubmitBase<TFieldValues extends FieldValues = FieldValues>(
121
+ props: FormAutoSubmitProps<TFieldValues>,
122
+ ) {
133
123
  const { wait, initialWait, maxWait, submit, parallel, ...watchOptions } = props
134
124
 
135
125
  // We create a stable object from the values, so that we can compare them later
@@ -157,17 +147,7 @@ function useFormAutoSubmit2<
157
147
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
158
148
  submitDebounced()
159
149
  }
160
- }
161
150
 
162
- /**
163
- * We're wrapping this in a component so that the parent component doesn't rerender on every
164
- * submission.
165
- */
166
- function FormAutoSubmitBase<
167
- TFieldValues extends FieldValues = FieldValues,
168
- TFieldNames extends readonly FieldPath<TFieldValues>[] = readonly FieldPath<TFieldValues>[],
169
- >(props: FormAutoSubmitProps<TFieldValues, TFieldNames>) {
170
- useFormAutoSubmit2(props)
171
151
  return null
172
152
  }
173
153