@graphcommerce/react-hook-form 8.0.3-canary.4 → 8.1.0-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,15 +1,8 @@
1
1
  # Change Log
2
2
 
3
- ## 8.0.3-canary.4
3
+ ## 8.1.0-canary.3
4
4
 
5
- ## 8.0.3-canary.3
6
-
7
- ### Patch Changes
8
-
9
- - [#2206](https://github.com/graphcommerce-org/graphcommerce/pull/2206) [`855ab09`](https://github.com/graphcommerce-org/graphcommerce/commit/855ab097b9ea204a7c73c6550b7a5e9e2290f378) - Cleanup `<FormAutoSubmit/>` and remove internal hook.
10
- ([@paales](https://github.com/paales))
11
-
12
- ## 8.0.3-canary.2
5
+ ## 8.1.0-canary.2
13
6
 
14
7
  ## 8.0.3-canary.1
15
8
 
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.4",
5
+ "version": "8.1.0-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.4",
20
- "@graphcommerce/prettier-config-pwa": "^8.0.3-canary.4",
21
- "@graphcommerce/typescript-config-pwa": "^8.0.3-canary.4",
19
+ "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.3",
20
+ "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.3",
21
+ "@graphcommerce/typescript-config-pwa": "^8.1.0-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,
8
9
  DeepPartialSkipArrayKey,
9
10
  FieldPath,
10
11
  FieldValues,
11
12
  UseFormReturn,
12
- UseWatchProps,
13
13
  useFormState,
14
14
  useWatch,
15
15
  } from 'react-hook-form'
@@ -98,8 +98,21 @@ export function useFormAutoSubmit<
98
98
  return submitting
99
99
  }
100
100
 
101
- export type FormAutoSubmitProps<TFieldValues extends FieldValues = FieldValues> = {
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>
102
107
  /** 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
103
116
 
104
117
  /** SubmitHandler */
105
118
  // eslint-disable-next-line react/no-unused-prop-types
@@ -111,15 +124,12 @@ export type FormAutoSubmitProps<TFieldValues extends FieldValues = FieldValues>
111
124
  */
112
125
  // eslint-disable-next-line react/no-unused-prop-types
113
126
  parallel?: boolean
114
- } & DebounceOptions &
115
- Omit<UseWatchProps<TFieldValues>, 'defaultValue'>
127
+ } & DebounceOptions
116
128
 
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
- ) {
129
+ function useFormAutoSubmit2<
130
+ TFieldValues extends FieldValues = FieldValues,
131
+ TFieldNames extends readonly FieldPath<TFieldValues>[] = readonly FieldPath<TFieldValues>[],
132
+ >(props: FormAutoSubmitProps<TFieldValues, TFieldNames>) {
123
133
  const { wait, initialWait, maxWait, submit, parallel, ...watchOptions } = props
124
134
 
125
135
  // We create a stable object from the values, so that we can compare them later
@@ -147,7 +157,17 @@ function FormAutoSubmitBase<TFieldValues extends FieldValues = FieldValues>(
147
157
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
148
158
  submitDebounced()
149
159
  }
160
+ }
150
161
 
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)
151
171
  return null
152
172
  }
153
173