How to use antd.Form.create in typescript?

  1. Import the FormComponentProps

    import {FormComponentProps} from 'antd/lib/form/Form';
    
  2. Then have your component

    interface YourProps {
        test: string;
    }        
    
    class YourComponent extends React.Component<YourProps & FormComponentProps> {
        constructor(props: YourProps & FormComponentProps) {
            super(props);
            ...
        }
    }
    
  3. Then export the class using Form.create()

    export default Form.create<YourProps>()(YourComponent);
    

    The generic argument on Form.create casts the result to a React ComponentClass with YourProps – without FormComponentProps, because these are being injected through the Form.create wrapper component.

Leave a Comment

tech