I am new to Typescript. How do you normally handle onChange
in TextField
, when using Typescript language?
- The function
handleChangeDate(e: React.ChangeEvent<any>)
in the code below works, but I get warnings because I use the typeany
. 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);
};
TS2345: Argument of type 'string' is not assignable to parameter of type 'SetStateAction '.
– Monochasium