Reputation: 2422
I recently learned about this. (what´s the name of it?)
condition && console.log("hello")
how can I use it with a component? like
condition && <MyComponent />
that´s it. thank you!
Upvotes: 2
Views: 127
Reputation: 807
It's possible to use inline for only true conditions:
{condition && <MyComponent />}
And for true and false conditions:
{condition ? <MyComponent /> : <MyFalseComponent />}
Upvotes: 2
Reputation: 4175
you can use it on component like this,
{condition && <MyComponent />}
See https://reactjs.org/docs/react-component.html#render this line in types
Booleans or null. Render nothing. (Mostly exists to support return test && pattern, where test is boolean.)
Upvotes: 5