Skip to content

Commit

Permalink
Merge pull request #7 from stevent-team/fix/proxy-init
Browse files Browse the repository at this point in the history
Make sure Proxies are always initialised with a valid object
  • Loading branch information
GRA0007 authored Jul 5, 2023
2 parents b2ee5eb + c6ab9cc commit db9d113
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-dryers-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stevent-team/react-zoom-form": patch
---

Always init Proxy with object
4 changes: 2 additions & 2 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export type PathSegment = {
* Thanks to [react-zorm](https://github.com/esamattis/react-zorm) for the inspiration.
*/
export const fieldChain = <S extends z.ZodType>(schema: S, path: PathSegment[], register: RegisterFn, controls: Omit<FieldControls<z.ZodTypeAny>, 'schema' | 'path'>): any =>
new Proxy(schema, {
new Proxy({}, {
get: (_target, key) => {
if (typeof key !== 'string') {
throw new Error(`${String(key)} must be a string`)
Expand Down Expand Up @@ -87,7 +87,7 @@ export const fieldChain = <S extends z.ZodType>(schema: S, path: PathSegment[],
}) as unknown

export const errorChain = <S extends z.ZodType>(schema: S, path: PathSegment[], error?: z.ZodError<z.infer<S>>): any =>
new Proxy(schema, {
new Proxy({}, {
get: (_target, key) => {
if (typeof key !== 'string') {
throw new Error(`${String(key)} must be a string`)
Expand Down

0 comments on commit db9d113

Please sign in to comment.