I am new to Typescript. How do you normally handle onChange
in TextField
, when using Typescript language?
handleChangeDate(e: React.ChangeEvent<any>)
in the code below works, but I get warnings because I use the type any
. Which other way can I write this code?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);
};
For MUI Textfield
event: React.ChangeEvent<HTMLInputElement>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With