I am getting a list object from api which looks like allSettings list. i want to set the state of each item on that list so I can use it to define the checked status of toggle and can change state when there is change on toggle.
const Settings = () => {
allSettings= [{name:"Setting1", value= true}, {name:"Setting2", value= true},
{name:"Setting3", value= true},{name:"Setting4", value= false},{name:"Setting5", value= true},
{name:"Setting6", value= true},{name:"Setting7", value= true}]
const[settings, setSettings]= useState({
// i want to set the state of all allsettings's item in here
});
function handleChange(evt) {
//to change state of toggle
}
return (
<div>
{
allsettings.map(item => {
return (
<div>
<Switch
checked= {item.value} //for now i am using item value
color="primary"
name={item.name}
inputProps={{ "aria-label": "primary checkbox" }}
onChange= {handleChange}
/>
<label>
{item.name}
</label>
</div>
);
})
}
</div>
);
}
export default Settings;