Ternary Operation
#
SyntaxYou can make your if-else
statement more concise by using a ternary operation.
#
For exampleImagine you have a toggle to switch between two modes, edit and view, in your component. The derived condition is a simple boolean. You can use the boolean to decide which element you want to return.
If your blocks in both branches of the ternary operation are getting bigger, you can use parentheses.
The ternary operation makes the conditional rendering in React more concise than the if-else
statement. It is simple to inline it in your return statement.