In my reactjs project, when I onchange the toggleswitch, I am getting the error as
Warning: Failed prop type: The prop `checked` is marked as required in `ToggleSwitch`, but its value is `undefined`.
I have an array which contains some values in which I need to map and to show the toggleswitch. my code is:
let [ischecked, setChecked] = useState({
checkedA: true,
});
const handleSwitchChange = (event, func) => {
setChecked(event);
};
Object.keys(arr).map((key, val) => (
<ToggleSwitch
className='onFunc'
defaultChecked={ischecked.checkedA}
onChange={(e)=>handleSwitchChange(e,key)}
name={`fun[${key}]`}
id={`on_${key}`}
optionLabels={["On", "Off"]}
value={ischecked.checkedA === true ? 'y' : 'n'}
/>
))
</td>
Pleas help. I don't know how to fix the issue.
I need to remove the console eror when i click on the toggleswitch.
This is happening because in your
ToggleSwitchcomponent you have this :This means that your
ToggleSwitchshould recieve a property namedchecked.so you have to pass it to the component :
if you don't really need it to be required you can remove
isRequired:so it will be optional