I know there is already a ton of questions same as mine (like this one.. ) But I could not find the perfect answer.
What i have to do
React v.15.6.2
I have to render several elements ordered by categories with JQuery Accordion, like in the image below :
Here is my render function :
public render():React.ReactElement<{}>{
return (
<div className={styles.extensionContainer}>
/* TONS OF DIV WITH CONTENT*/
<div className="accordion">
{this.state.items.map((item:CategoryArray)=>
<h3>{item.CategoryName}</h3>
<div className={styles.answers}>
{item.Items.map((x)=>
<h3>{x.ItemTitle}</h3>
<div className={styles.answer} dangerouslySetInnerHTML={{__html: x.ItemAnswer}}></div>
)}
</div>
)}
</div>
</div>
);
}
But unforutnately it is not working, and the build throws me the following errors :
error TS2657 : JSX expressions mus have one parent element. error TS2695 : Left side of comma operator is unused and has no side effects
What I tried :
- At first, I was wrapping my first
.map()
results in a<div className="accordion">
, but my jQuery Accordion widget got a little bugged because of that. That made me search for another solution. - I tried to wrap it only with a simple
<div>
but it is absolutely not rendering my accordion correctly. - I tried to wrap it in
<>
and</>
(as said in the answers of this thread - I even tried to wrap it with
<Fragment></Fragment>
by installing Babel-cli and importing fragment, but there is no chances in that either.
And now this leaves me with no more solutions. Not rendering well, or absolut bug, do you have any idea on How to render my accordion without wrapping every single item in a div , please ?
Thanks a lot ! Have a nice day!