question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ref is not defined on FormProp type

See original GitHub issue

Description

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

  1. 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:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
mattcosta7commented, Mar 17, 2021

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

// @rjsf/material-ui.   Form
import Form from '@rjsf/core'
const MuiForm: typeof Form = withTheme(them);

should make the ref (and the generic for formData) play much nicer

0reactions
cdolekcommented, Nov 30, 2022

Now that core has been converted to Typescript this should be fixed in the v5 beta

for themed forms, can not set ref using beta.13 - any workarounds for this?

... is not assignable to type 'IntrinsicAttributes & FormProps<any, any>'.
Property 'ref' does not exist on type 'IntrinsicAttributes & FormProps<any, any>
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found