diff --git a/docs/refactor/00-table-of-contents.md b/docs/refactor/00-table-of-contents.md index 1d07b817..ed5a3937 100644 --- a/docs/refactor/00-table-of-contents.md +++ b/docs/refactor/00-table-of-contents.md @@ -30,10 +30,11 @@ Handling user input Scaling up: using multiple components - Motivation: separate concerns - Composition example -- Ownership +- Ownership (and owner vs. parent) - Data flow (one-way data binding) - A note on performance - You should build a reusable component library (CSS, testing etc) +- Prop validation - Mixins - Testing @@ -42,9 +43,10 @@ Forms - How to think about Reactive forms - New form events and properties -Touching the DOM +Working with the browser - Refs / getDOMNode() - Component lifecycle +- Polyfills Integrating with other UI libraries - Using jQuery plugins @@ -64,6 +66,7 @@ Big ideas - Bootstrap bindings (responsive grids) - Reactive CSS - Web workers +- Native views Case studies - Comment box tutorial from scratch diff --git a/docs/refactor/01-motivation.md b/docs/refactor/01-motivation.md index aeb7898d..7cc413a9 100644 --- a/docs/refactor/01-motivation.md +++ b/docs/refactor/01-motivation.md @@ -6,7 +6,7 @@ We built React to solve one problem: **building large applications with data tha ## Stay simple and declarative -React apps are easy to write. Think of your UI as a state machine; simply express how the UI should look at any given point in time, and React will manage all UI updates for you when your underlying data changes. +React apps are easy to write. Simply express how the UI should look at any given point in time, and React will manage all UI updates for you when your underlying data changes. It's just like writing a server-rendered web app: when the data changes, React conceptually hits the refresh button, except React is very fast and maintains the state of your UI. Because of this, React's API is very small and easy to understand. diff --git a/docs/refactor/02-displaying-data.md b/docs/refactor/02-displaying-data.md index 4da127bd..14c6ca17 100644 --- a/docs/refactor/02-displaying-data.md +++ b/docs/refactor/02-displaying-data.md @@ -59,10 +59,12 @@ The inputs to this component are called `props` -- short for "properties". They' React components are very simple. You can think of them as simple function that take in `props` and `state` (discussed later) and render HTML. Because they're so simple, it makes them very easy to reason about. +**One limitation**: React components can only render a single root node. If you want to return multiple nodes they *must* be wrapped in a single root. This is a limitation we can fix, but we have not identified a pressing reason to do so yet; reach out to our [Google Group](http://groups.google.com/group/reactjs) if you have a compelling case for it. + ## 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. -JSX is very small; the example above uses every feature of JSX. To learn more about it, see [JSX in depth](./02.1-jsx-in-depth.md) \ No newline at end of file +JSX is very small; the example above uses every feature of JSX. To learn more about it, see [JSX in depth](./02.1-jsx-in-depth.md). \ No newline at end of file diff --git a/docs/refactor/03-handling-user-input.md b/docs/refactor/03-handling-user-input.md index 79f8e35f..030a15a7 100644 --- a/docs/refactor/03-handling-user-input.md +++ b/docs/refactor/03-handling-user-input.md @@ -46,6 +46,8 @@ Under the hood React does a few things to keep your code performant and easy to React thinks of UIs as simple state machines. By thinking of a UI as being in various states and rendering those states, it's easy to keep your UI consistent. +In React, you simply update a component's state, and then render a new UI based on this new state. React takes care of updating the DOM for you in the most efficient way. + ## How state works A common way to inform React of a data change is by calling `setState(data, callback)`. This method merges `data` into `this.state` and re-renders the component. When the component finishes re-rendering, the optional `callback` is called. Most of the time you'll never need to provide a `callback` since state tends to be so minimal. diff --git a/docs/refactor/04-scaling-up.md b/docs/refactor/04-scaling-up.md index 0b301f50..6fe5f7b5 100644 --- a/docs/refactor/04-scaling-up.md +++ b/docs/refactor/04-scaling-up.md @@ -4,12 +4,80 @@ So far, we've looked at how to write a single component to display data and hand ## Motivation: separation of concerns -By building modular components that reuse other components using well-definted interfaces, you get much of the same benefits that you get by using functions or classes. Specifically you can *separate the different concerns* of your app however you please simply by building new components. By building a custom component library for your application, you are expressing your UI in a way that best fits your domain. +By building modular components that reuse other components with well-defined interfaces, you get much of the same benefits that you get by using functions or classes. Specifically you can *separate the different concerns* of your app however you please simply by building new components. By building a custom component library for your application, you are expressing your UI in a way that best fits your domain. ## Composition example +Let's create a simple Avatar component which shows a profile picture and username using the Facebook Graph API. + ```javascript /** @jsx React.DOM */ +var Avatar = React.createClass({ + render: function() { + return ( +