The library for web and native user interfaces.
Cleanup "Reference"
(unlinked likebutton tutorial - not updated enough for public)
Paul O’Shannessy committed
Jul 16, 2013 at 23:31 UTC
c222f57b0029c3a5b2935a08805fbe122465768e
1 file changed
+38
-8
docs/docs/09-reference.md
+38
-8
@@ -5,33 +5,38 @@ layout: docs
5
permalink: reference.html
6
prev: tooling-integration.html
7
---
8
+
9
## Examples
10
11
+
12
### Production Apps
13
14
* All of [Instagram.com](http://instagram.com/) is built on React.
15
* Many components on [Facebook.com](http://www.facebook.com/), including the commenting interface, ads creation flows, and page insights.
16
* [Khan Academy](http://khanacademy.org/) is using React for its question editor.
17
18
+
19
### Sample Code
20
18
-* We've included **[a step-by-step comment box tutorial](./tutorial.md)**
19
-* There is also [a simple LikeButton tutorial](./likebutton/)
20
-* [The React starter kit](/react/downloads.md) includes several examples which you can [view online in our GitHub repo](https://github.com/facebook/react/tree/master/examples/)
21
+* We've included [a step-by-step comment box tutorial](./tutorial.md).
22
+* [The React starter kit](/react/downloads.html) includes several examples which you can [view online in our GitHub repository](https://github.com/facebook/react/tree/master/examples/).
23
* [reactapp](https://github.com/jordwalke/reactapp) is a simple app template to get you up-and-running quickly with React.
24
* [React one-hour email](https://github.com/petehunt/react-one-hour-email/commits/master) goes step-by-step from a static HTML mock to an interactive email reader (written in just one hour!)
25
* [Rendr + React app template](https://github.com/petehunt/rendr-react-template/) demonstrates how to use React's server rendering capabilities.
26
27
+
28
## API
29
30
### React
31
32
`React` is the entry point to the React framework. If you're using one of the prebuilt packages it's available as a global; if you're using CommonJS modules you can `require()` it.
33
34
+
35
#### React.DOM
36
37
`React.DOM` provides all of the standard HTML tags needed to build a React app. You generally don't use it directly; instead, just include it as part of the `/** @jsx React.DOM */` docblock.
38
39
+
40
#### React.initializeTouchEvents
41
42
```javascript
@@ -40,6 +45,7 @@ initializeTouchEvents(boolean shouldUseTouch)
45
46
Configure React's event system to handle touch events on mobile devices.
47
48
+
49
#### React.createClass
50
51
```javascript
@@ -48,6 +54,7 @@ function createClass(object specification)
54
55
Creates a component given a specification. A component implements a `render` method which returns **one single** child. That child may have an arbitrarily deep child structure. One thing that makes components different than a standard prototypal classes is that you don't need to call new on them. They are convenience wrappers that construct backing instances (via new) for you.
56
57
+
58
#### React.renderComponent
59
60
```javascript
@@ -58,6 +65,7 @@ Renders a React component into the DOM in the supplied `container`.
65
66
If the React component was previously rendered into `container`, this will perform an update on it and only mutate the DOM as necessary to reflect the latest React component.
67
68
+
69
#### React.unmountAndReleaseReactRootNode
70
71
```javascript
@@ -66,6 +74,7 @@ unmountAndReleaseReactRootNode(DOMElement container)
74
75
Remove a mounted React component from the DOM and clean up its event handlers and state.
76
77
+
78
#### React.renderComponentToString
79
80
```javascript
@@ -74,16 +83,19 @@ renderComponentToString(ReactComponent component, function callback)
83
84
Render a component to its initial HTML. This should only be used on the server. React will call `callback` with an HTML string when the markup is ready. You can use this method to create static site generators, or you can generate HTML on the server and send it down to have a very fast initial page load. If you call `React.renderComponent()` on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.
85
86
+
87
### AbstractEvent
88
89
Your event handlers will be passed instances of `AbstractEvent`, a cross-browser wrapper around the browser's native event. It has the same interface as the browser's native event (such as `stopPropagation()` and `preventDefault()`) except they work exactly the same across all browsers.
90
91
If you find that you need the underlying browser event for some reason, simply use the `nativeEvent` attribute to get it.
92
93
+
94
### ReactComponent
95
96
Component classses created by `createClass()` return instances of `ReactComponent` when called. Most of the time when you're using React you're either creating or consuming `ReactComponent`s.
97
98
+
99
#### getDOMNode
100
101
```javascript
@@ -92,6 +104,7 @@ DOMElement getDOMNode()
104
105
If this component has been mounted into the DOM, this returns the corresponding native browser DOM element. This method is useful for reading values out of the DOM, such as form field values and performing DOM measurements.
106
107
+
108
#### setProps
109
110
```javascript
@@ -100,7 +113,10 @@ setProps(object nextProps)
113
114
When you're integrating with an external JavaScript application you may want to signal a change to a React component rendered with `renderComponent()`. Simply call `setProps()` to change its properties and trigger a re-render.
115
103
-**Note:** This method can only be called on a root-level component. That is, it's only available on the component passed directly to `renderComponent()` and none of its children. If you're inclined to use `setProps()` on a child component, instead take advantage of reactive updates and pass the new prop to the child component when it's created in `render()`.
116
+> Note:
117
+>
118
+> This method can only be called on a root-level component. That is, it's only available on the component passed directly to `renderComponent()` and none of its children. If you're inclined to use `setProps()` on a child component, instead take advantage of reactive updates and pass the new prop to the child component when it's created in `render()`.
119
+
120
121
#### replaceProps
122
@@ -110,6 +126,7 @@ replaceProps(object nextProps)
126
127
Like `setProps()` but deletes any pre-existing props that are not in nextProps.
128
129
+
130
#### transferPropsTo
131
132
```javascript
@@ -118,6 +135,7 @@ ReactComponent transferPropsTo(ReactComponent targetComponent)
135
136
Transfer properties from this component to a target component that have not already been set on the target component. This is usually used to pass down properties to the returned root component. `targetComponent`, now updated with some new props is returned as a convenience.
137
138
+
139
#### setState
140
141
```javascript
@@ -126,11 +144,18 @@ setState(object nextState[, function callback])
144
145
Merges nextState with the current state. This is the primary method you use to trigger UI updates from event handlers and server request callbacks. In addition, you can supply an optional callback function that is executed once `setState` is completed.
146
129
-**Note:** *NEVER* mutate `this.state` directly. As calling `setState()` afterwards may replace the mutation you made. Treat `this.state` as if it were immutable.
147
+> Note:
148
+>
149
+> *NEVER* mutate `this.state` directly. As calling `setState()` afterwards may replace the mutation you made. Treat `this.state` as if it were immutable.
150
+
151
+> Note:
152
+>
153
+> `setState()` does not immediately mutate `this.state` but creates a pending state transition. Accessing `this.state` after calling this method can potentially return the existing value.
154
131
-**Note:** `setState()` does not immediately mutate `this.state` but creates a pending state transition. Accessing `this.state` after calling this method can potentially return the existing value.
155
+> Note:
156
+>
157
+> There is no guarantee of synchronous operation of calls to `setState` and calls may be batched for performance gains.
158
133
-**Note**: There is no guarantee of synchronous operation of calls to `setState` and calls may be batched for performance gains.
159
160
#### replaceState
161
@@ -140,6 +165,7 @@ replaceState(object nextState[, function callback])
165
166
Like `setState()` but deletes any pre-existing state keys that are not in nextState.
167
168
+
169
#### forceUpdate()
170
171
```javascript
@@ -150,7 +176,10 @@ If your `render()` method reads from something other than `this.props` or `this.
176
177
Normally you should try to avoid all uses of `forceUpdate()` and only read from `this.props` and `this.state` in `render()`. This makes your application much simpler and more efficient.
178
153
-**Note**: There is no guarantee of synchronous operation of calls to `forceUpdate` and calls may be batched for performance gains.
179
+> Note:
180
+>
181
+> There is no guarantee of synchronous operation of calls to `forceUpdate` and calls may be batched for performance gains.
182
+
183
184
#### Lifecycle methods
185
@@ -168,6 +197,7 @@ componentWillUnmount()
197
198
See the [working with the browser](./working-with-the-browser.html) documentation for more details on these lifecycle methods.
199
200
+
201
## DOM Differences
202
203
React has implemented a browser-independent events and DOM system for performance and cross-browser compatibility reasons. We took the opportunity to clean up a few rough edges in browser DOM implementations.