you can simply use ternary in render component . so let’s see bellow example that will help you to understand how it works. First example will cover react ternary statement in render function.
Read moreWhat is a ternary operator JS?
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.
Read moreHow do you use the operator in React?
The three dots syntax (…) is part of ES6 and not React itself and it’s used by two operators i.e. the Spread and Rest operators. The Spread operator lets you expand an iterable like an object, string, or array into its elements while the Rest operator does the inverse by reducing a set of elements into one array .
Read moreWhat is ternary operator in React?
The ternary operator is a simplified conditional operator like if / else . Syntax: condition ? < expression if true> : <expression if false>
Read more