Merge pull request #2076 from whatasunnyday/master

Add example to if else in JSX.
This commit is contained in:
Paul O’Shannessy
2014-08-20 12:45:04 -07:00
+21
View File
@@ -39,4 +39,25 @@ That's not valid JS. You probably want to make use of a ternary expression:
React.renderComponent(<div id={condition ? 'msg' : ''}>Hello World!</div>, mountNode);
```
If a ternary expression isn't robust enough, you can use `if` statements to determine which
components should be used.
```js
/** @jsx React.DOM */
var loginButton;
if (loggedIn) {
loginButton = <LogoutButton />;
} else {
loginButton = <LoginButton />;
}
return (
<nav>
<Home />
{loginButton}
</nav>
)
```
Try using it today with the [JSX compiler](/react/jsx-compiler.html).