Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 conditional if statement to check if arrays are empty [duplicate]

I can't seem to get my jsx es6 react if statement to work.. What am I doing wrong?

const otherVariables = doesntMatter;    

return (
...
    <div>
    {if (props.student.length == null && props.teacher.length == null) => (
       <p>empty</p>
    ) : (
       <p>not empty</p>
    )} 
   </div>
...
)

How can i check if both arrays are empty?

like image 653
Modelesq Avatar asked Dec 25 '22 05:12

Modelesq


1 Answers

There is a syntax error, you are testing an lambda expression.

You can do something like

return !!props.student.length && !!props.teacher.length ? <p>not empty</p> : <p>empty</p>;
like image 118
Rosmarine Popcorn Avatar answered Dec 26 '22 20:12

Rosmarine Popcorn