мой код компонента формы здесь:
import * as React from 'react';
import { From } from 'antd';
import { FormComponentProps } from 'antd/es/form';
import CustomControl from './CustomControl'
interface IProps extends FormComponentProps {
}
class MyForm extends React.Component<IProps> {
constructor(props: IProps) {
super(props);
}
public render(): React.ReactNode {
const { getFieldDecorator } = this.props.form
return <Form>
<Form.Item label="custom-control">
{
getFieldDecorator('custom-field', {initialValue: 'custome-value'})
(<CustomControl />)
}
</Form.Item>
</Form>
}
}
export default Form.create<IProps>()(MyForm);
мой элемент управления формы настройки здесь:
import * as React from 'react';
import { Input } from 'antd';
const { forwardRef, useState } = React;
function CustomControl(props: any) {
const [value, setValue] = useState(props.value);
const handleChange = (value: string) => {
if (props.onChange) {
setValue(value)
props.onChange(value)
}
}
return <div>
<Input value={value} onChange=((e) => handleChange(e.currentTarget.value)) />
</div>
}
export default forwardRef(CustomControl)
вот это any
:
function CustomComponent(props: any) {}
я могуне определите тип этого реквизита, который прошел мимо antd
getFieldDecorator
, код в antd о getFieldDecorator
:
getFieldDecorator<T extends Object = {}>(id: keyof T, options?: GetFieldDecoratorOptions): (node: React.ReactNode) => React.ReactNode;
React.ReactNode
явно не для меня.
Так, я могу написать только any
здесь, это не достаточно дружелюбно.
Пожалуйста, покажите мне способ оптимизировать это any
.