You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The template syntax in React is called [JSX](http://facebook.github.io/react/docs/displaying-data.html#jsx-syntax). It is allowed in JSX to put HTML tags directly into JavaScript codes. React.render() is the method which translates JSX into HTML, and renders it into the specified DOM node.
52
52
@@ -171,7 +171,7 @@ The desired DOM node should have a `ref` attribute, and `React.findDOMNode(this.
171
171
172
172
## Demo07: this.state
173
173
174
-
React thinks of component as state machines, and uses `this.state` to hold component's state, `getInitialState()` to initialize `this.state`, `this.setState()` to update `this.state` and re-render the component.
174
+
React thinks of component as state machines, and uses `this.state` to hold component's state, `getInitialState()` to initialize `this.state`(invoked before a component is mounted), `this.setState()` to update `this.state` and re-render the component.
175
175
176
176
```js
177
177
var LikeButton =React.createClass({
@@ -203,7 +203,7 @@ You could use component attributes to register event handlers, just like `onClic
203
203
204
204
According to React's design philosophy, `this.state` describes the state of component and is mutated via user interactions, and `this.props` describes the properties of component and is stable adn immutable.
205
205
206
-
Since that, the `value` attribute of Form components, such as <input$gt;, <textarea$gt;, and <option$gt;, is unaffected by any user input. If you wanted to access or update the value in response to user input, you could use the onChange event.
206
+
Since that, the `value` attribute of Form components, such as <input>, <textarea>, and <option>, is unaffected by any user input. If you wanted to access or update the value in response to user input, you could use the onChange event.
207
207
208
208
```js
209
209
var Input =React.createClass({
@@ -231,7 +231,7 @@ More information on [officail document](http://facebook.github.io/react/docs/for
231
231
232
232
## Demo09: Component Lifecycle
233
233
234
-
Components have three main parts of their lifecycle: Mounting, Updatingand Unmounting. React provides hooks into these lifecycle part. `will` methods are called right before something happens, and `did` methods which are called right after something happens.
234
+
Components have three main parts of [their lifecycle](https://facebook.github.io/react/docs/working-with-the-browser.html#component-lifecycle): Mounting(being inserted into the DOM), Updating(being re-rendered) and Unmounting(being removed from the DOM). React provides hooks into these lifecycle part. `will` methods are called right before something happens, and `did` methods which are called right after something happens.
235
235
236
236
```js
237
237
var Hello =React.createClass({
@@ -269,9 +269,19 @@ React.render(
269
269
);
270
270
```
271
271
272
+
The following is [a whole list of lifecycle methods](http://facebook.github.io/react/docs/component-specs.html#lifecycle-methods).
- componentWillReceiveProps(object nextProps): invoked when a mounted component receives new props.
280
+
- shouldComponentUpdate(object nextProps, object nextState): invoked when a component decides whether any changes warrant an update to the DOM.
281
+
272
282
## Demo10: Ajax
273
283
274
-
Fetch data in componentDidMount. When the response arrives, store the data in state, triggering a render to update your UI.
284
+
How to get the data of a component from a server or an API provider? The answer is using Ajax to fetch data in the event handler of `componentDidMount`. When the server response arrives, store the data with `this.setState()` to trigger a re-render of your UI.
This demo is copied from [github.com/mhart/react-server-example](https://github.com/mhart/react-server-example), but I rewrote it with JSX syntax.
326
+
327
+
```bash
328
+
# install the dependencies in demo11 directory
329
+
$ npm install
330
+
331
+
# translate all jsx file in src subdirectory to js file
// copied from https://github.com/mhart/react-server-examplei
1
+
This demo is copied from [github.com/mhart/react-server-example](https://github.com/mhart/react-server-example), but I rewrote it with JSX syntax.
2
2
3
-
$ npm install
4
-
$ jsx src/ .
5
-
$ node server.js
3
+
```bash
4
+
# install the dependencies in demo11 directory
5
+
$ npm install
6
+
7
+
# translate all jsx file in src subdirectory to js file
0 commit comments