[material-ui][FormControl] Typescript error: Cannot access e.target.checked
#41843
Labels
component: FormControl
The React component
package: material-ui
Specific to @mui/material
typescript
Steps to reproduce
Link to live example: https://stackblitz.com/edit/react-lt4tqf?file=Demo.tsx%3AL184
Current behavior
No response
Expected behavior
No response
Context
Im trying to figure out how to type
FormControlLabel.onChange
so we can accesse.target.checked
?using
React.SyntheticEvent<HTMLInputElement>
doesnt let us access.checked
and when I change it to
React.ChangeEvent<HTMLInputElement>
it works but then I get a different type error when passing the function toFormControlLabel.onChange
I could pass this to
Switch.onChange
but in my actual code, Im passingname="<some-name>"
to theFormControlLabel
which lets me accesse.target.name
in the event handler so I can reuse state logic.Your environment
npx @mui/envinfo
These might not be the latest but using latest in stackblitz
https://stackblitz.com/edit/react-lt4tqf?file=Demo.tsx,node_modules%2F%40mui%2Fmaterial%2FFormControlLabel%2FFormControlLabel.d.ts
Search keywords: e.target.checked
The text was updated successfully, but these errors were encountered: