is it possible to use inline if with react components?

Viewed 51

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!

2 Answers

It's possible to use inline for only true conditions:

{condition && <MyComponent />}

And for true and false conditions:

{condition ? <MyComponent /> : <MyFalseComponent />}
Related