Issue
How can I call function before the component in if statement? I have syntax error with this.
Here are the codes:
<AccordionDetails>
{answers.map((a) => (
Number(a.SoruID) === Number(soru.SoruID) ?
getAnswerCount(a.SoruID, a.Id),
<Typography>
{a.TextCevap} kullanicilar :{cevapSayisi}
</Typography>
:null
))}
</AccordionDetails>
I'm stackoverflow newbie, I used screenshot instead of the code before, sorry for this.
Solution
You should use the full syntax, if the short syntax does not suit you.
<AccordionDetails>
{answers.map((a) => {
if (Number(a.SoruID) === Number(soru.SoruID)){
const totalAnswers = getAnswerCount(a.SoruID, a.Id);
return (
<Typography>
{a.TextCevap} ..... {totalAnswers}
</Typography>
);
}
return null;
})
</AccordionDetails>
Answered By - Gabriele Petrioli
Answer Checked By - - Dawn Plyler (ReactFix Volunteer)