Ref is not defined on FormProp type
See original GitHub issueDescription
The following documentation example produces an error when compiling with typescript : https://react-jsonschema-form.readthedocs.io/en/latest/advanced-customization/internals/#submit-form-programmatically
Steps to Reproduce
- Copy the example from https://react-jsonschema-form.readthedocs.io/en/latest/advanced-customization/internals/#submit-form-programmatically:
const onSubmit = ({formData}) => console.log("Data submitted: ", formData);
let yourForm;
const schema = {
type: "string"
};
render((
<Form schema={schema}
onSubmit={onSubmit} ref={(form) => {yourForm = form;}}/>
), document.getElementById("app"));
yourForm.submit();
Expected behavior
It should compile without problems
Actual behavior
When compiling with tsc
No overload matches this call.
Overload 1 of 2, '(props: FormProps<any>, context?: any): ReactElement<any, any> | Component<FormProps<any>, any, any> | null', gave the following error.
Type '{ children: Element; schema: JSONSchema7; liveValidate: true; noHtml5Validate: true; showErrorList: false; ref: (form: any) => void; onSubmit: (values: Record<string, any>)
e to type 'IntrinsicAttributes & FormProps<any>'.
Property 'ref' does not exist on type 'IntrinsicAttributes & FormProps<any>'.
Overload 2 of 2, '(props: PropsWithChildren<FormProps<any>>, context?: any): ReactElement<any, any> | Component<FormProps<any>, any, any> | null', gave the following error.
Type '{ children: Element; schema: JSONSchema7; liveValidate: true; noHtml5Validate: true; showErrorList: false; ref: (form: any) => void; onSubmit: (values: Record<string, any>)
e to type 'IntrinsicAttributes & FormProps<any> & { children?: ReactNode; }'.
Property 'ref' does not exist on type 'IntrinsicAttributes & FormProps<any> & { children?: ReactNode; }'. TS2769
> 47 | ref={form => {
| ^
48 | yourForm = form;
49 | }}
50 | onSubmit={onSubmit}
Version
"react": "^16.9.0",
"typescript": "^3.8.3",
"@rjsf/antd": "^2.4.0",
"@rjsf/core": "^2.4.0",
"@types/react": "^16.9.43",
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:14 (8 by maintainers)
Top Results From Across the Web
ReactJs: refs is not defined (no-undef) - Stack Overflow
In the following code, I wrapped your code a function component and use React.createRef() to create a ref and assign to okanhzai.
Read more >property ref does not exist on type intrinsicattributes - You.com
So the main problem here is that you're returning the result of React.forwardRef in your render, which isn't a valid return type for...
Read more >TS Support | React Hook Form - Simple React forms validation
This type is useful when you define custom component's name prop, and it will type check again your field path. Copy. export type...
Read more >Final Form Docs – `FormProps`
A render function that is given FormRenderProps , as well as any non-API props passed into the <Form/> component. For example, if you...
Read more >Form - Ant Design
If you are using class component, you can get it by ref . expand code ... Set component disabled, only works for antd...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@JoeryH thanks again for that repro and update.
Opened a PR for the typing updates here - feel free to make a similar change locally and report back if this works on your end as well.
should make the ref (and the generic for formData) play much nicer
for themed forms, can not set
ref
usingbeta.13
- any workarounds for this?