Home > Software design >  React Multiple Condition Check(JSX)
React Multiple Condition Check(JSX)

Time:11-15

I've been trying to do some conditional rendering based on the user that is logged in. Is there a way in React JSX to check if more than one condition is true? I know this syntax is wrong but is there a way I can do this with just JSX. I basically want to check if the post array is empty and if the loading variable is false.

{filteredPosts.length === 0 && loading === false ? "This user has no posts" :  <Posts loading={loading} fetchData={fetchData} posts={filteredPosts}/>}

CodePudding user response:

try this

{(filteredPosts.length === 0 && loading === false) ? "This user has no posts" :  <Posts loading={loading} fetchData={fetchData} posts={filteredPosts}/>}
  • Related