@graphcommerce/react-hook-form 7.1.0-canary.21 → 7.1.0-canary.22
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 +6 -0
- package/package.json +4 -4
- package/src/useFormGql.tsx +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 7.1.0-canary.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2097](https://github.com/graphcommerce-org/graphcommerce/pull/2097) [`cdc89cedb`](https://github.com/graphcommerce-org/graphcommerce/commit/cdc89cedb9eb4d37a2c37497689e74ff6df21bf6) - Set default value of `experimental_v2` to false in `useFormGql`, since we don't want an experimental feature as default ([@mikekeehnen](https://github.com/mikekeehnen))
|
|
8
|
+
|
|
3
9
|
## 7.1.0-canary.21
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
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": "7.1.0-canary.
|
|
5
|
+
"version": "7.1.0-canary.22",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"react-hook-form": "7.46.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@graphcommerce/eslint-config-pwa": "7.1.0-canary.
|
|
20
|
-
"@graphcommerce/prettier-config-pwa": "7.1.0-canary.
|
|
21
|
-
"@graphcommerce/typescript-config-pwa": "7.1.0-canary.
|
|
19
|
+
"@graphcommerce/eslint-config-pwa": "7.1.0-canary.22",
|
|
20
|
+
"@graphcommerce/prettier-config-pwa": "7.1.0-canary.22",
|
|
21
|
+
"@graphcommerce/typescript-config-pwa": "7.1.0-canary.22",
|
|
22
22
|
"@testing-library/react": "^14.0.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
package/src/useFormGql.tsx
CHANGED
|
@@ -81,7 +81,7 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
81
81
|
form,
|
|
82
82
|
tuple,
|
|
83
83
|
defaultValues,
|
|
84
|
-
experimental_useV2
|
|
84
|
+
experimental_useV2 = false,
|
|
85
85
|
} = options
|
|
86
86
|
const { encode, type, ...gqlDocumentHandler } = useGqlDocumentHandler<Q, V>(document)
|
|
87
87
|
const [execute, { data, error, loading }] = tuple
|
|
@@ -93,7 +93,7 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
93
93
|
const controllerRef = useRef<AbortController | undefined>()
|
|
94
94
|
const valuesString = JSON.stringify(defaultValues)
|
|
95
95
|
useEffect(() => {
|
|
96
|
-
if (
|
|
96
|
+
if (experimental_useV2) return
|
|
97
97
|
|
|
98
98
|
if (initital.current) {
|
|
99
99
|
initital.current = false
|
|
@@ -108,7 +108,7 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
108
108
|
form.handleSubmit(async (formValues, event) => {
|
|
109
109
|
// Combine defaults with the formValues and encode
|
|
110
110
|
submittedVariables.current = undefined
|
|
111
|
-
let variables =
|
|
111
|
+
let variables = experimental_useV2 ? formValues : encode({ ...defaultValues, ...formValues })
|
|
112
112
|
|
|
113
113
|
// Wait for the onBeforeSubmit to complete
|
|
114
114
|
if (onBeforeSubmit) {
|
|
@@ -119,7 +119,7 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
119
119
|
// if (variables === false) onInvalid?.(formValues, event)
|
|
120
120
|
|
|
121
121
|
submittedVariables.current = variables
|
|
122
|
-
if (loading &&
|
|
122
|
+
if (loading && experimental_useV2) controllerRef.current?.abort()
|
|
123
123
|
controllerRef.current = new window.AbortController()
|
|
124
124
|
const result = await execute({
|
|
125
125
|
variables,
|
|
@@ -129,7 +129,7 @@ export function useFormGql<Q, V extends FieldValues>(
|
|
|
129
129
|
if (onComplete && result.data) await onComplete(result, variables)
|
|
130
130
|
|
|
131
131
|
// Reset the state of the form if it is unmodified afterwards
|
|
132
|
-
if (typeof diff(form.getValues(), formValues) === 'undefined' && !
|
|
132
|
+
if (typeof diff(form.getValues(), formValues) === 'undefined' && !experimental_useV2)
|
|
133
133
|
form.reset(formValues)
|
|
134
134
|
|
|
135
135
|
await onValid(formValues, event)
|