Issue
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);
};
Solution
For MUI TextField (v5.10.11)
event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>
Answered By - keikai
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.