diff --git a/docs/docs/08-working-with-the-browser.md b/docs/docs/08-working-with-the-browser.md index aec2aaa270..4e2c7ff909 100644 --- a/docs/docs/08-working-with-the-browser.md +++ b/docs/docs/08-working-with-the-browser.md @@ -56,10 +56,9 @@ React provides lifecycle methods that you can specify to hook into this process. ### Mounted Methods -_Mounted_ composite components also support the following methods: +_Mounted_ composite components also support the following method: -* `findDOMNode(): DOMElement` can be invoked on any mounted component in order to obtain a reference to its rendered DOM node. -* `forceUpdate()` can be invoked on any mounted component when you know that some deeper aspect of the component's state has changed without using `this.setState()`. +* `component.forceUpdate()` can be invoked on any mounted component when you know that some deeper aspect of the component's state has changed without using `this.setState()`. ## Browser Support and Polyfills diff --git a/docs/docs/08.1-more-about-refs.md b/docs/docs/08.1-more-about-refs.md index 8eefaab1c8..f1ae11f92a 100644 --- a/docs/docs/08.1-more-about-refs.md +++ b/docs/docs/08.1-more-about-refs.md @@ -63,9 +63,9 @@ or using an ES6 arrow function: }, ``` -Note that when the referenced component is unmounted and whenever the ref changes, the old ref will be called with `null` as an argument. This prevents memory leaks in the case that the instance is stored, as in the first example. Also note that when writing refs with inline function expressions as in the examples here, React sees a different function object each time so on every update, ref will be called with `null` immediately before it's called with the component instance. +When attaching a ref to a DOM component like `
`, you get the DOM node back; when attaching a ref to a composite component like ``, you'll get the React class instance. In the latter case, you can call methods on that component if any are exposed in its class definition. -You can access the component's DOM node directly by calling `ReactDOM.findDOMNode(argumentToYourCallback)`. +Note that when the referenced component is unmounted and whenever the ref changes, the old ref will be called with `null` as an argument. This prevents memory leaks in the case that the instance is stored, as in the first example. Also note that when writing refs with inline function expressions as in the examples here, React sees a different function object each time so on every update, ref will be called with `null` immediately before it's called with the component instance. ## The ref String Attribute @@ -81,11 +81,11 @@ React also supports using a string (instead of a callback) as a ref prop on any 2. In some other code (typically event handler code), access the **backing instance** via `this.refs` as in: ```javascript - this.refs.myInput + var input = this.refs.myInput; + var inputValue = input.value; + var inputRect = input.getBoundingClientRect(); ``` - You can access the component's DOM node directly by calling `ReactDOM.findDOMNode(this.refs.myInput)`. - ## A Complete Example In order to get a reference to a React component, you can either use `this` to get the current React component, or you can use a ref to get a reference to a component you own. They work like this: @@ -120,7 +120,7 @@ ReactDOM.render( In this example, we get a reference to the text input **backing instance** and we call `focus()` when the button is clicked. -For composite components, the reference will refer to an instance of the component class so you can invoke any methods that are defined on that class. If you need access to the underlying DOM node for that component, you can use [ReactDOM.findDOMNode](/react/docs/top-level-api.html#reactdom.finddomnode). +For composite components, the reference will refer to an instance of the component class so you can invoke any methods that are defined on that class. If you need access to the underlying DOM node for that component, you can use [ReactDOM.findDOMNode](/react/docs/top-level-api.html#reactdom.finddomnode) as an "escape hatch" but we don't recommend it since it breaks encapsulation and in almost every case there's a clearer way to structure your code within the React model. ## Summary @@ -128,13 +128,13 @@ Refs are a great way to send a message to a particular child instance in a way t ### Benefits: -- You can define any public method on your component classes (such as a reset method on a Typeahead) and call those public methods through refs (such as `this.refs.myTypeahead.reset()`). -- Performing DOM measurements almost always requires reaching out to a "native" component such as `` and accessing its underlying DOM node via `ReactDOM.findDOMNode(this.refs.myInput)`. Refs are one of the only practical ways of doing this reliably. +- You can define any public method on your component classes (such as a reset method on a Typeahead) and call those public methods through refs (such as `this.refs.myTypeahead.reset()`). In most cases, it's clearer to use the built-in React data flow instead of using refs imperatively. +- Performing DOM measurements almost always requires reaching out to a "native" component such as `` and accessing its underlying DOM node using a ref. Refs are one of the only practical ways of doing this reliably. - Refs are automatically managed for you! If that child is destroyed, its ref is also destroyed for you. No worrying about memory here (unless you do something crazy to retain a reference yourself). ### Cautions: - *Never* access refs inside of any component's render method - or while any component's render method is even running anywhere in the call stack. -- If you want to preserve Google Closure Compiler Crushing resilience, make sure to never access as a property what was specified as a string. This means you must access using `this.refs['myRefString']` if your ref was defined as `ref="myRefString"`. +- If you want to preserve Google Closure Compiler advanced-mode crushing resilience, make sure to never access as a property what was specified as a string. This means you must access using `this.refs['myRefString']` if your ref was defined as `ref="myRefString"`. - If you have not programmed several apps with React, your first inclination is usually going to be to try to use refs to "make things happen" in your app. If this is the case, take a moment and think more critically about where `state` should be owned in the component hierarchy. Often, it becomes clear that the proper place to "own" that state is at a higher level in the hierarchy. Placing the state there often eliminates any desire to use `ref`s to "make things happen" – instead, the data flow will usually accomplish your goal. - Refs may not be attached to a [stateless function](/react/docs/reusable-components.html#stateless-functions), because the component does not have a backing instance. You can always wrap a stateless component in a standard composite component and attach a ref to the composite component. diff --git a/docs/docs/10-addons.md b/docs/docs/10-addons.md index d076bd122b..a0a5cc5063 100644 --- a/docs/docs/10-addons.md +++ b/docs/docs/10-addons.md @@ -6,7 +6,7 @@ prev: tooling-integration.html next: animation.html --- -`React.addons` is where we park some useful utilities for building React apps. **These should be considered experimental** but will eventually be rolled into core or a blessed utilities library: +The React add-ons are a collection of useful utility modules for building React apps. **These should be considered experimental** and tend to change more often than the core. - [`TransitionGroup` and `CSSTransitionGroup`](animation.html), for dealing with animations and transitions that are usually not simple to implement, such as before a component's removal. - [`LinkedStateMixin`](two-way-binding-helpers.html), to simplify the coordination between user's form input data and the component's state. @@ -20,6 +20,4 @@ The add-ons below are in the development (unminified) version of React only: - [`TestUtils`](test-utils.html), simple helpers for writing test cases (unminified build only). - [`Perf`](perf.html), for measuring performance and giving you hint where to optimize. -To get the add-ons, use `react-with-addons.js` (and its minified counterpart) rather than the common `react.js`. - -When using the react package from npm, simply `require('react/addons')` instead of `require('react')` to get React with all of the add-ons. +To get the add-ons, install them individually from npm (e.g., `npm install react-addons-pure-render-mixin`). We don't support using the addons if you're not using npm. diff --git a/docs/docs/10.1-animation.md b/docs/docs/10.1-animation.md index bccdcc98f8..5cc1defe88 100644 --- a/docs/docs/10.1-animation.md +++ b/docs/docs/10.1-animation.md @@ -17,7 +17,7 @@ React provides a `ReactTransitionGroup` addon component as a low-level API for a `ReactCSSTransitionGroup` is the interface to `ReactTransitions`. This is a simple element that wraps all of the components you are interested in animating. Here's an example where we fade list items in and out. ```javascript{28-30} -var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup; +var ReactCSSTransitionGroup = require('react-addons-css-transition-group'); var TodoList = React.createClass({ getInitialState: function() { @@ -173,7 +173,7 @@ In order for it to apply transitions to its children, the `ReactCSSTransitionGro In the example above, we rendered a list of items into `ReactCSSTransitionGroup`. However, the children of `ReactCSSTransitionGroup` can also be one or zero items. This makes it possible to animate a single element entering or leaving. Similarly, you can animate a new element replacing the current element. For example, we can implement a simple image carousel like this: ```javascript{10-12} -var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup; +var ReactCSSTransitionGroup = require('react-addons-css-transition-group'); var ImageCarousel = React.createClass({ propTypes: { @@ -201,7 +201,7 @@ You can disable animating `enter` or `leave` animations if you want. For example ## Low-level API: `ReactTransitionGroup` -`ReactTransitionGroup` is the basis for animations. It is accessible as `React.addons.TransitionGroup`. When children are declaratively added or removed from it (as in the example above) special lifecycle hooks are called on them. +`ReactTransitionGroup` is the basis for animations. It is accessible from `require('react-addons-transition-group')`. When children are declaratively added or removed from it (as in the example above) special lifecycle hooks are called on them. ### `componentWillAppear(callback)` @@ -237,11 +237,7 @@ By default `ReactTransitionGroup` renders as a `span`. You can change this behav ``` -Every DOM component that React can render is available for use. However, `component` does not need to be a DOM component. It can be any React component you want; even ones you've written yourself! - -> Note: -> -> Prior to v0.12, when using DOM components, the `component` prop needed to be a reference to `React.DOM.*`. Since the component is simply passed to `React.createElement`, it must now be a string. Composite components must pass the factory. +Every DOM component that React can render is available for use. However, `component` does not need to be a DOM component. It can be any React component you want; even ones you've written yourself! Just write `component={List}` and your component will receive `this.props.children`. Any additional, user-defined, properties will become properties of the rendered component. For example, here's how you would render a `