|
|
@ -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). |
|
|
|