【发布时间】:2020-07-20 20:45:32
【问题描述】:
我是 Typescript 的新手。 TextField中的onChange,在使用Typescript语言的时候,一般是怎么处理的?
- 下面代码中的函数
handleChangeDate(e: React.ChangeEvent<any>)可以工作,但我收到警告,因为我使用了any类型。我还可以通过什么其他方式编写此代码?
import React, { useState } from 'react';
import { useForm } from 'react-hook-form';
import { TextField } from '@material-ui/core';
const [date, setDate] = useState(
new Date().getDate() + '/' + (new Date().getMonth() + 1) + '/' + new Date().getFullYear(),
);
const handleChangeDate = (e: React.ChangeEvent<any>): void => {
setDate(e.target.value);
};
【问题讨论】:
标签: reactjs typescript material-ui tsx