reactjs - what's the props's type with Typescript when i customize ant-design form control
问题描述
my form component code here:
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);
my customize form control here:
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)
it's this any
:
function CustomComponent(props: any) {}
i can't define this props's type who's passed by antd
getFieldDecorator
, the code in antd about getFieldDecorator
:
getFieldDecorator<T extends Object = {}>(id: keyof T, options?: GetFieldDecoratorOptions): (node: React.ReactNode) => React.ReactNode;
React.ReactNode
is obviously not for me.
So, i can only write any
here, it's not friendly enough.
Please show me the way to optimize this any
.
解决方案
推荐阅读
- android - 如何删除 Android 滑块底部效果?
- blockchain - 为什么以太坊区块链中的合约被称为“智能合约”?
- c++ - 什么是模板<>模板
语法? - ruby-on-rails - 使用 rabbitMQ(cloudamqp 插件)在 heroku 上的配置问题 - ruby 应用程序
- python - PyCharm 不会安装 pycurl macOS High Sierra
- javascript - 无法使用 ajax 发送更大的 json(array) 数据
- javascript - Jspdf-自动行跨度修复
- php - Woocommerce codeigniter Rest API
- azure - Azure 容器实例 - 公开端口以绑定 443 (HTTPS)
- sql - 使用查询完成sql同步