remix-params-helper
remix-params-helper copied to clipboard
Support refine/ZodEffects in useFormInputProps
Passing a ZodEffects (output of using refine
) into useFormInputProps
will result in inputProps
function that cannot find any of your keys.
I believe the problem is here where it is assuming there is a schema.shape
when there may actually be a schema._def.schema.shape
:
https://github.com/kiliman/remix-params-helper/blob/e7e2c24f340622bce8a2ef8f61ee76bbe8281196/src/helper.ts#L185
Current work around:
const realSchema = schema instanceof ZodEffects ? schema._def.schema : schema;
const inputProps = useFormInputProps(realSchema);
Thanks. Yeah, the internal Zod schema can get very complex. Since I don't use every feature of Zod, I'll handle edge cases like this as they come up.
@conform-to/react
with @conform-to/zod
supports more complex zod schemas, but that packages feels a bit complex for what I'm doing. I really like the simplicity of useFormInputProps
, but I also need refine.
Yes, remix-params-helper
was meant as a simple interface, so it only supported features that I actually used and not everything that zod can do.
See #32 for more info.