I am using accordion from mui where I am using map() function to add data to each accordion. For onChange event of a particular accordion, handleChange is be called because of which that accordion should expand, but all the accordions are been expanded rather than the one for which the handleChange is called! How to fix this?
Code for handle change:
const [expanded, setExpanded] = React.useState('panel1');
const handleChange = (panel) => (event, newExpanded) => {
console.log(panel);
setExpanded(newExpanded ? panel : false);
};
Code returned inside react component:
<Container sx={{ paddingBlock: "4rem" }}>
{faqData.map((faq, index) =>
<Accordion key={index} expanded={expanded === ('panel' + { index })} onChange={handleChange('panel' + { index })}>
<AccordionSummary aria-controls={('panel' + { index } + 'd - content')} id={('panel' + { index } + 'd-header')}>
<Typography>{faq[0]}</Typography>
</AccordionSummary>
<AccordionDetails>
<Typography>
{faq[1]}
</Typography>
</AccordionDetails>
</Accordion>
)}
</Container>