From 67d9891926417dba53bf1641a0b2ac4b42f3d768 Mon Sep 17 00:00:00 2001 From: petehunt Date: Wed, 10 Jul 2013 16:56:43 -0700 Subject: [PATCH] add seconds 02.1 and 03 --- docs/docs/refactor/00-table-of-contents.md | 1 + docs/docs/refactor/02-displaying-data.md | 157 +----------------- docs/docs/refactor/02.1-jsx-in-depth.md | 161 +++++++++++++++++++ docs/docs/refactor/03-handling-user-input.md | 59 +++++++ 4 files changed, 224 insertions(+), 154 deletions(-) create mode 100644 docs/docs/refactor/02.1-jsx-in-depth.md create mode 100644 docs/docs/refactor/03-handling-user-input.md diff --git a/docs/docs/refactor/00-table-of-contents.md b/docs/docs/refactor/00-table-of-contents.md index e19c3edfba..9ae050cdb9 100644 --- a/docs/docs/refactor/00-table-of-contents.md +++ b/docs/docs/refactor/00-table-of-contents.md @@ -14,6 +14,7 @@ Handling user input - Under the hood: autoBind and event delegation (IE8 notes) - How state works - What should go in state? +- What components should have state? Scaling up: using multiple components - Motivation: separate concerns diff --git a/docs/docs/refactor/02-displaying-data.md b/docs/docs/refactor/02-displaying-data.md index 29f6189059..6e2b856027 100644 --- a/docs/docs/refactor/02-displaying-data.md +++ b/docs/docs/refactor/02-displaying-data.md @@ -53,163 +53,12 @@ setInterval(function() { View the finished code in a web browser and type your name into the text field. Notice that React is only changing the time string in the UI -- any input you put in the text field remains, even though you haven't written any code to manage this behavior. React figures it out for you and does the right thing. +The inputs to this component are called `props` -- short for "properties". They're passed as attributes in JSX syntax. You should think of these as immutable within the component, that is, **never write to this.props**. + ## JSX syntax 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. -### 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 =