Closed YassineDM closed 4 years ago
Can you remove the defaultCheck prop from the component and instead put a default value into initialValues and see if this resolves your issue? (i.e. initialValues={{customSwitch: true}}
Default values on ant design components do not work.
You're right, it is 'fixed'. And now that you mention it, it seems that default values do not work. Do you know why?
It is by design, however not well documented. Formik does all form state management. So values (including initial values), touches, submissions, errors are managed with formik. It does not make sense to put initial values onto ant design components, because formik would not "see" them. It also does not make sense to hook into ant designs defaultValue and set values on formik. Formik already provides a mechanism to set defaults (the initialValues prop).
Ok this makes sense, thank you for the explanation...
Importing the Switch component fires this warning in the console:
The implementation is rather straightforward:
I don't know if it is part of the issue but the
defaultChecked
prop is not taken into account...By the way, I successfully imported other components such as Checkbox, DatePicker, Input, InputNumber, Radio & SubmitButton.
Relevant packages: