remix-params-helper icon indicating copy to clipboard operation
remix-params-helper copied to clipboard

Support refine/ZodEffects in useFormInputProps

Open WesleyKapow opened this issue 2 years ago • 3 comments

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);

WesleyKapow avatar May 27 '22 18:05 WesleyKapow

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.

kiliman avatar May 27 '22 22:05 kiliman

@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.

hilja avatar Jan 20 '24 13:01 hilja

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.

kiliman avatar Jan 22 '24 16:01 kiliman