Using Inline Ternary Operator
Conditionally Spreading the Object Properties
We can use ternary or logical &&
operator, along with the spread operator, to conditionally add props to a component like so:
<Tooltip
message={message}
// using the ternary operator
{...(!isMobile ? { position: 'left' } : {})}
// using the logical && operator
{...(!isMobile && { position: 'left' })}
>
<InfoIcon />
</Tooltip>