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

The FormProps interface should include the ref prop and the Form class should include the state generic. #2186

Closed
3 tasks done
Steffan-Ennis opened this issue Jan 4, 2021 · 1 comment

Comments

@Steffan-Ennis
Copy link

Steffan-Ennis commented Jan 4, 2021

Prerequisites

Description

  • The ref prop has not been described in the FormProps interface
  • The state generic has not been described in the Form as part of the the Form React component

Steps to Reproduce

const MyForm = ({FormDefinition, formData, onDesignChange}) => {

  const jsonSchemaFormRef = React.createRef<RJSF.default<any>>()

  const onChangeHandler = ({formdata}) => {
     jsonSchemaFormRef.current?.validate()  

     if (jsonSchemaFormRef.current?.state.errors.length == 0){
        onDesignChange(formData)
      }
  }      

  return (
    <JsonSchemaForm
      schema={formDefinition.schema as JSONSchema7 }
      uiSchema={formDefinition.uiSchema as JSONSchema7 }
      ref={jsonSchemaFormRef} // Ref is available on all react class elements
      onChange={onChangeHandler} 
      formData={formData}>
  )
}

Expected behavior

Should compile without any errors

Actual behavior

Compiles with the following typescript errors

TS2339: Property 'errors' does not exist on type 'Readonly<{}>'.
      TS2769: 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: any[]; schema: JSONSchema7; uiSchema: JSONSchema7; ref: RefObject<Form<any>>; formData: IPropertyPanelFormData | undefined; FieldTemplate: ({ id, children, displayLabel, rawErrors, rawHelp, rawDescription, }: FieldTemplateProps) => Element; onChange: DebouncedFunc<...>; }' is not assignable 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: any[]; schema: JSONSchema7; uiSchema: JSONSchema7; ref: RefObject<Form<any>>; formData: IPropertyPanelFormData | undefined; FieldTemplate: ({ id, children, displayLabel, rawErrors, rawHelp, rawDescription, }: FieldTemplateProps) => Element; onChange: DebouncedFunc<...>; }' is not assignable to type 'IntrinsicAttributes & FormProps<any> & { children?: ReactNode; }'.
      Property 'ref' does not exist on type 'IntrinsicAttributes & FormProps<any> & { children?: ReactNode; }'.

Version

2.4.0

@heath-freenome
Copy link
Member

Fixed in the v5 beta, see the 5.x migration guide

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

No branches or pull requests

3 participants