mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #2076 from whatasunnyday/master
Add example to if else in JSX.
This commit is contained in:
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user