jolly-crimson
jolly-crimson2y ago

update switch on api response

Hello !! I'm currently using refine to make an app and i have a from in which i set every field with register but i have a switch which is not updating even if the value from react hook form is correct. For the other mui component ( Textfiled, select ...) i do not have to create a state to have the correct value in the field but the switch is not working. Should i make a state for switch only ?
5 Replies
afraid-scarlet
afraid-scarlet2y ago
Hi 👋 This should work as expected. please change name field according to your field name.
<Controller
control={control}
name="active"
render={({
field: { onChange, onBlur, value, name, ref },
}) => (
<Switch
name={name}
onBlur={onBlur}
onChange={onChange}
checked={value}
inputRef={ref}
/>
)}
/>
<Controller
control={control}
name="active"
render={({
field: { onChange, onBlur, value, name, ref },
}) => (
<Switch
name={name}
onBlur={onBlur}
onChange={onChange}
checked={value}
inputRef={ref}
/>
)}
/>
if this not work please reproduce the issue on some platform. i will happy to debug 🙏
jolly-crimson
jolly-crimson2y ago
Thank you @alicanerdurmaz ! where can i find the documentation about this ?
afraid-scarlet
afraid-scarlet2y ago
jolly-crimson
jolly-crimson2y ago
It work perfectly !! Thank you
afraid-scarlet
afraid-scarlet2y ago
I'm glad to hear that 👊 have a nice day 🚀