issue: MUI Checkbox is not showing the checkbox checked if initially set to true using setValue #11707
Replies: 2 comments
-
it seems like you're setting the default values for your form fields using setValue. Instead of this useEffect, you can set defaultValue inside useForm: const { register, handleSubmit, control } = useForm<FormType>({
defaultValues: {
live1: true,
live2: `_${new Date().getTime()}`,
live3: true,
},
}); Also, you can make more controlled component: <Controller
control={control}
name='live1'
render={({ field: { onChange, value } }) => (
<FormControlLabel
control={<Checkbox checked={value} onChange={onChange} />}
label='Label 1'
/>
)}
/>; |
Beta Was this translation helpful? Give feedback.
-
if you use another Checkbox Component like ( , Ant Design) just under warning is happen. But its working well. ** But material-ui is sensetive for checkbox inititalValue. and if initalValue is undefined under error is happen , And does'nt work in first rendering. **MUI: A component is changing the uncontrolled checked state of SwitchBase to be controlled. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Version Number
7.51.1
Codesandbox/Expo snack
https://stackblitz.com/edit/vitejs-vite-r3mrgb?file=src%2FApp.tsx
Steps to reproduce
Result:{"live1":true,"live3":true,"live2":"_1711090817282"}
Expected behaviour
Live1 checkbox should show as checked in the UI
What browsers are you seeing the problem on?
Firefox, Chrome, Safari, Edge
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions