jsx conditional formatting code example
Example 1: conditional rendering react
function Mailbox(props) {
const unreadMessages = props.unreadMessages;
return (
<div>
<h1>Hello!</h1>
{unreadMessages.length > 0 && <h2> You have {unreadMessages.length} unread messages. </h2> } </div>
);
}
const messages = ['React', 'Re: React', 'Re:Re: React'];
ReactDOM.render(
<Mailbox unreadMessages={messages} />,
document.getElementById('root')
);
Example 2: how to change grid size with conditional expression in react
<Grid.Column width={ condition ? <column number if true> : <column number if false> } />
<Grid item xs={12} sm={isLogic ? 8 : 12}></Grid>