I'm getting an infinite rerender when I try to make a controlled accordian component using the material ui accordian. Here is my code, anybody have any ideas why it might be causing an infinite rerender?
const [expanded, setExpanded] = React.useState([true, false, false]);
const handleChange = idx => {
const newState = expanded.map((value, i) => (i === idx ? !value : value));
setExpanded(newState);
};
And then the expanded and onChange props on the Accordian component are written as so:
<Accordion expanded={expanded[0]} onChange={handleChange(0)}>
You don't need an array to do it.
Add a unique id to each Accordion like this
<Accordion expanded={expanded === "first"} onChange={setExpanded("first")} />