From b9cf0d2bddf451167a8c8ea82b3f2d81c2a66935 Mon Sep 17 00:00:00 2001 From: Sunny Juneja Date: Wed, 20 Aug 2014 11:43:26 -0700 Subject: [PATCH] Add example to if else in JSX. --- docs/tips/03-if-else-in-JSX.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/tips/03-if-else-in-JSX.md b/docs/tips/03-if-else-in-JSX.md index 5a04c9f60e..91105b655a 100644 --- a/docs/tips/03-if-else-in-JSX.md +++ b/docs/tips/03-if-else-in-JSX.md @@ -39,4 +39,25 @@ That's not valid JS. You probably want to make use of a ternary expression: React.renderComponent(
Hello World!
, 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 = ; +} else { + loginButton = ; +} + +return ( + +) +``` + Try using it today with the [JSX compiler](/react/jsx-compiler.html).