From 7f14b384996083211367b6e7ca56e9536919ad3a Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Wed, 23 Oct 2013 16:08:59 -0400 Subject: [PATCH] entry on `false` behavior --- cookbook/13-false-in-jsx tip.md | 29 +++++++++++++++++++++++++++++ cookbook/13-false-in-jsx.md | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 cookbook/13-false-in-jsx tip.md create mode 100644 cookbook/13-false-in-jsx.md diff --git a/cookbook/13-false-in-jsx tip.md b/cookbook/13-false-in-jsx tip.md new file mode 100644 index 00000000..a419c0af --- /dev/null +++ b/cookbook/13-false-in-jsx tip.md @@ -0,0 +1,29 @@ +--- +id: false-in-jsx-tip +title: False in JSX +layout: cookbook +permalink: initial-ajax.html +prev: initial-ajax.html +--- + +Here's how `false` renders in different contexts: + +Renders as `id="false"`: +```js +/** @jsx React.DOM */ +React.renderComponent(
, mountNode); +``` + +String "false" as input value: +```js +/** @jsx React.DOM */ +React.renderComponent(, mountNode); +``` + +No child: +```js +/** @jsx React.DOM */ +React.renderComponent(
{false}
, mountNode); +``` + +The reason why this one doesn't render as the string `"false"` as a `div` child is to allow the more common use-case: `
{x > 1 && You have more than one item}
`. diff --git a/cookbook/13-false-in-jsx.md b/cookbook/13-false-in-jsx.md new file mode 100644 index 00000000..9c5ac438 --- /dev/null +++ b/cookbook/13-false-in-jsx.md @@ -0,0 +1,32 @@ +--- +id: false-in-jsx +title: False in JSX +layout: cookbook +permalink: initial-ajax.html +prev: initial-ajax.html +--- + +### Problem +How does `undefined` and `false` behave as attribute value and as child component? + +### Solution +Renders as `id="false"`: +```js +/** @jsx React.DOM */ +React.renderComponent(
, mountNode); +``` + +String "false" as input value: +```js +/** @jsx React.DOM */ +React.renderComponent(, mountNode); +``` + +No child: +```js +/** @jsx React.DOM */ +React.renderComponent(
{false}
, mountNode); +``` + +### Discussion +The reason why the last one doesn't render as the string `"false"` as a `div` child is to allow the more common use-case: `
{x > 1 && You have more than one item}
`.