Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

最新版本的react-hook-form和rc-input-number是9.3.0版本时出现Illegal invocation错误 #684

Open
gavin99587 opened this issue Dec 15, 2024 · 0 comments

Comments

@gavin99587
Copy link

"react": "18.3.1",
"react-dom": "18.3.1",
"rc-input-number": "^9.3.0",
"@hookform/resolvers": "^3.9.1",
"react-hook-form": "^7.54.1",

用以上版本时,
如下代码
import { Box, Form } from 'grommet';
import { z } from 'zod';
import { SubmitHandler, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import InputNumber from 'rc-input-number';

const zodFormSchema = z.object({
orderQty: z.coerce.number().positive('必须正数'),
});

type ZodFormFieldsProps = z.infer;
/**

  • 测试inputNumber组件
  • */
    export default function TestInputNumber() {
    const { register, handleSubmit, setValue } = useForm({
    resolver: zodResolver(zodFormSchema),
    });

const onOrderQtyChange = (val: string | number | null) => {
setValue('orderQty', val ? parseFloat(val + '') : 0, {
shouldValidate: true,
shouldTouch: true,
shouldDirty: true,
});
};
const onFormSubmit: SubmitHandler = (formData) => {
console.log('formData', formData);
};

return (


<InputNumber
{...register('orderQty')}
min={0}
step={1}
onChange={onOrderQtyChange}
/>


);
}

会报
hook.js:608 React Router caught the following error during render TypeError: Illegal invocation
at Proxy.set (react-dom.development.js:1661:1)错误
但是如果将"rc-input-number": "^9.0.0",改为此版本,上面其他内容都不变,则不会报错,使用正常

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant