Datastores11
Datastores11

Reputation: 123

react native why is my condition not working?

I want to show components when one of the three product categorys are selected.

Its not working.

 { step === 2 && (product.category.category_name === 'clothing') || (product.category.category_name === 'accessoires') || (product.category.category_name === 'shoes') && return (<View><Text>Hello</Text></View> ) }

If clothing or accessoires or shoes exists then I want to show a component. Its not working why ? If I remove all except clothing then it works.

Upvotes: 0

Views: 121

Answers (1)

Manuel
Manuel

Reputation: 133

I think you should chain better your conditionals && and ||.

Try this code:

if (step === 2) 
{ 
 if (product.category.category_name === 'clothing' ||
     product.category.category_name === 'accessoires' ||
     product.category.category_name === 'shoes' )
   { 
     return (<View><Text>Hello</Text></View> )
   }
 }

Upvotes: 1

Related Questions