Skip to content

Commit b378db0

Browse files
committed
edit README
1 parent 130579d commit b378db0

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

README.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ These demos are purposely written in a simple and clear style. You will find no
77
- [Webpack Demos](https://github.com/ruanyf/webpack-demos)
88
- [Flux Demo 01](https://github.com/ruanyf/flux-for-stupid-people-demo)
99
- [Flux Demo 02](https://github.com/ruanyf/flux-todomvc-demo)
10+
- [A boilerplate for React-Babel-Webpack project](https://github.com/ruanyf/react-babel-webpack-boilerplate)
1011

1112
## How to use
1213

@@ -110,7 +111,7 @@ ReactDOM.render(
110111

111112
`React.createClass()` creates a component class, which implements a render method to return an component instance of the class. You don't need to call `new` on the class in order to get an instance, just use it as a normal HTML tag.
112113

113-
```js
114+
```javascript
114115
var HelloMessage = React.createClass({
115116
render: function() {
116117
return <h1>Hello {this.props.name}</h1>;
@@ -123,7 +124,32 @@ ReactDOM.render(
123124
);
124125
```
125126

126-
Components can have attributes, and you can use `this.props.[attribute]` to access them, just like `this.props.name` of `<HelloMessage name="John" />` is John.
127+
Components would have attributes, and you can use `this.props.[attribute]` to access them, just like `this.props.name` of `<HelloMessage name="John" />` is John.
128+
129+
Please remember the first letter of the component's name must be capitalized, otherwise React will throw an error. For instance, `HelloMessage` as a component's name is OK, but `helloMessage` is not allowed. And a React component should only one top child node.
130+
131+
```javascript
132+
// wrong
133+
var HelloMessage = React.createClass({
134+
render: function() {
135+
return <h1>
136+
Hello {this.props.name}
137+
</h1><p>
138+
some text
139+
</p>;
140+
}
141+
});
142+
143+
// correct
144+
var HelloMessage = React.createClass({
145+
render: function() {
146+
return <div>
147+
<h1>Hello {this.props.name}</h1>
148+
<p>some text</p>
149+
</div>;
150+
}
151+
});
152+
```
127153

128154
## Demo05: this.props.children ([source](https://github.com/ruanyf/react-demos/blob/master/demo05/index.html))
129155

@@ -348,13 +374,13 @@ ReactDOM.render(
348374

349375
The following is [a whole list of lifecycle methods](http://facebook.github.io/react/docs/component-specs.html#lifecycle-methods).
350376

351-
- componentWillMount()
352-
- componentDidMount()
353-
- componentWillUpdate(object nextProps, object nextState)
354-
- componentDidUpdate(object prevProps, object prevState)
355-
- componentWillUnmount()
356-
- componentWillReceiveProps(object nextProps): invoked when a mounted component receives new props.
357-
- shouldComponentUpdate(object nextProps, object nextState): invoked when a component decides whether any changes warrant an update to the DOM.
377+
- **componentWillMount()**: Fired once, before initial rendering occurs. Good place to wire-up message listeners. `this.setState` doesn't work here.
378+
- **componentDidMount()**: Fired once, after initial rendering occurs. Can use `this.getDOMNode()`.
379+
- **componentWillUpdate(object nextProps, object nextState)**: Fired after the component's updates are made to the DOM. Can use `this.getDOMNode()` for updates.
380+
- **componentDidUpdate(object prevProps, object prevState)**: Invoked immediately after the component's updates are flushed to the DOM. This method is not called for the initial render. Use this as an opportunity to operate on the DOM when the component has been updated.
381+
- **componentWillUnmount()**: Fired immediately before a component is unmounted from the DOM. Good place to remove message listeners or general clean up.
382+
- **componentWillReceiveProps(object nextProps)**: Fired when a component is receiving new props. You might want to `this.setState` depending on the props.
383+
- **shouldComponentUpdate(object nextProps, object nextState)**: Fired before rendering when new props or state are received. `return false` if you know an update isn't needed.
358384

359385
## Demo11: Ajax ([source](https://github.com/ruanyf/react-demos/blob/master/demo11/index.html))
360386

0 commit comments

Comments
 (0)