I want to modify my code where it allows me to open multiple questions at once, because in this code it only opens one. when I opened another question, the previous one closes.
import React, { useState } from "react";
import "./faq.css";
function Faq() {
const [selected, setSelected] = useState(null);
const toggle = (id) => {
if (selected === id) {
return setSelected(null);
}
setSelected(id);
};
return (
<div className="container">
<h2>Frequently Asked Questions</h2>
<div className="questions">
{Questions.map((question) => (
<div key={question.id}>
<h4>
{question.title}
<button onClick={() => toggle(question.id)}>
{selected === question.id ? "X" : "+"}
</button>
</h4>
<p
className={selected === question.id ? "question-info" : "hidden"}
>
{question.info}
</p>
</div>
))}
</div>
</div>
);
}
export default Faq;
Here is my code and I can’t solve this problem