Merge pull request #2076 from whatasunnyday/master

Add example to if else in JSX.
This commit is contained in:
Paul O’Shannessy
2014-09-03 15:50:40 -07:00
parent f77df86595
commit be5e3c5ef4
+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).