@graphcommerce/react-hook-form 3.2.2 → 3.3.2
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 +18 -0
- package/package.json +2 -2
- package/src/useFormGql.tsx +13 -0
- package/src/useGqlDocumentHandler.tsx +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 3.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1573](https://github.com/graphcommerce-org/graphcommerce/pull/1573) [`02023d8d8`](https://github.com/graphcommerce-org/graphcommerce/commit/02023d8d89c8138144243edce67290bd79ff49a7) Thanks [@paales](https://github.com/paales)! - useGqlDocumentHandler would not encode array items correctly
|
|
8
|
+
|
|
9
|
+
## 3.3.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1553](https://github.com/graphcommerce-org/graphcommerce/pull/1553) [`4a4579bb2`](https://github.com/graphcommerce-org/graphcommerce/commit/4a4579bb2f7da378f3fcc504405caf2560dc10f6) Thanks [@NickdeK](https://github.com/NickdeK)! - When using a useFormGqlMutation or useFormGqlQuery and defaultValues change, the form values will update for fields that aren't dirty.
|
|
14
|
+
|
|
15
|
+
## 3.3.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#1544](https://github.com/graphcommerce-org/graphcommerce/pull/1544) [`5f927ebdc`](https://github.com/graphcommerce-org/graphcommerce/commit/5f927ebdc6f0331833e02b96e4f169bfe475ac6b) Thanks [@mikekeehnen](https://github.com/mikekeehnen)! - Fixed hydration errors on account, cart and wishlist
|
|
20
|
+
|
|
3
21
|
## 3.2.2
|
|
4
22
|
|
|
5
23
|
### 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": "3.
|
|
5
|
+
"version": "3.3.2",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"type-fest": "^2.12.2"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@apollo/client": "^3.6.
|
|
22
|
+
"@apollo/client": "^3.6.9",
|
|
23
23
|
"graphql": "16.5.0",
|
|
24
24
|
"react-hook-form": "7.32.0"
|
|
25
25
|
},
|
package/src/useFormGql.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
ApolloError,
|
|
8
8
|
LazyQueryResultTuple,
|
|
9
9
|
} from '@apollo/client'
|
|
10
|
+
import { useEffect, useRef } from 'react'
|
|
10
11
|
import { UseFormProps, UseFormReturn, UnpackNestedValue, DeepPartial } from 'react-hook-form'
|
|
11
12
|
import diff from './diff'
|
|
12
13
|
import { useGqlDocumentHandler, UseGqlDocumentHandler } from './useGqlDocumentHandler'
|
|
@@ -51,6 +52,18 @@ export function useFormGql<Q, V>(
|
|
|
51
52
|
const [execute, { data, error }] = tuple
|
|
52
53
|
const client = useApolloClient()
|
|
53
54
|
|
|
55
|
+
// automatically updates the default values
|
|
56
|
+
const initital = useRef(true)
|
|
57
|
+
const valuesString = JSON.stringify(defaultValues)
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (initital.current) {
|
|
60
|
+
initital.current = false
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
form.reset(defaultValues, { keepDirtyValues: true })
|
|
64
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
|
+
}, [valuesString, form])
|
|
66
|
+
|
|
54
67
|
const handleSubmit: UseFormReturn<V>['handleSubmit'] = (onValid, onInvalid) =>
|
|
55
68
|
form.handleSubmit(async (formValues, event) => {
|
|
56
69
|
// Combine defaults with the formValues and encode
|
|
@@ -124,7 +124,7 @@ export function handlerFactory<Q, V>(document: TypedDocumentNode<Q, V>): UseGqlD
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
function encodeItem(enc: FieldTypes, val: unknown) {
|
|
127
|
-
if (Array.isArray(
|
|
127
|
+
if (Array.isArray(val)) return val.map((v, i) => encodeItem(enc[i], v))
|
|
128
128
|
if (val && typeof val === 'object') {
|
|
129
129
|
return Object.fromEntries(
|
|
130
130
|
Object.entries(val).map(([key, v]) => [key, heuristicEncode(v as string)]),
|