diff --git a/docs/refactor/02-displaying-data.md b/docs/refactor/02-displaying-data.md index c036afe3..29f61890 100644 --- a/docs/refactor/02-displaying-data.md +++ b/docs/refactor/02-displaying-data.md @@ -57,4 +57,159 @@ View the finished code in a web browser and type your name into the text field. We strongly believe that components are the right way to separate concerns rather than "templates" and "display logic." We think that markup and the code that generates it are intimately tied together. Additionally, display logic is often very complex and using template languages to express it becomes cumbersome. -We've found that the best solution for this problem is to generate markup directly from the JavaScript code such that you can use all of the expressive power of a real programming language to build UIs. In order to make this easier, we've added a *very* simple, **optional** HTML-like syntax for the function calls that generate markup called JSX. See [the JSX syntax documentation](syntax.html) for more information. \ No newline at end of file +We've found that the best solution for this problem is to generate markup directly from the JavaScript code such that you can use all of the expressive power of a real programming language to build UIs. In order to make this easier, we've added a *very* simple, **optional** HTML-like syntax for the function calls that generate markup called JSX. + +### Don't use JSX if you don't like it! + +React works out of the box without JSX. Simply construct your markup using the +functions on `React.DOM`. For example, here's how to construct a simple link: + +```javascript +var link = React.DOM.a({href: 'http://facebook.github.io/react'}, 'React'); +``` + +However, we recommend using JSX for many reasons: + +- It's easier to visualize the structure of the DOM. +- Designers are more comfortable making changes. +- It's familiar for those who have used MXML or XAML. + +### The Transform + +JSX transforms XML-like syntax into native JavaScript. It turns XML elements and +attributes into function calls and objects, respectively. + +```javascript +var Nav; +// Input (JSX): +var app = ; +// Output (JS): +var app = Nav({color:'blue'}, null); +``` + +Notice that in order to use ``, the `Nav` variable must be in scope. + +JSX also allows specifying children using XML syntax: + +```javascript +var Nav, Profile; +// Input (JSX): +var app = ; +// Output (JS): +var app = Nav({color:'blue'}, Profile(null, 'click')); +``` + +Use the [JSX Compiler](/react/jsx-compiler.html) to try out JSX and see how it +desugars into native JavaScript. + +If you want to use JSX, the [Getting Started](getting-started.html) guide shows +how to setup compilation. + +> Note: +> +> Details about the code transform are given here to increase understanding, but +> your code should not rely on these implementation details. + +### React and JSX + +React and JSX are independent technologies, but JSX was primarily built with +React in mind. The two valid uses of JSX are: + +- To construct instances of React DOM components (`React.DOM.*`). +- To construct instances of composite components created with + `React.createClass()`. + +**React DOM Components** + +To construct a `