I want to toggle the visibility of the div content on button click. For this, I'm using UseId hook as below
function toggleElement(elm_id) {
var el = document.getElementById(elm_id).nextElementSibling;
if (el.style.display === "block") {
el.style.display = "none";
} else {
el.style.display = "block";
}
}
function FAQ(props) {
const clickedElm = useId();
return (
<div className="faq-item">
<button type="button" id = {clickedElm} class="collapsible" onClick={toggleElement(this.id)} >
{props.question}
</button>
<div className="content">
<p>{props.answer}</p>
</div>
The above code is showing Error Boundaries not used error. I'm beginner to React. I didn't understand what it is. Where the code is going wrong?