Skip to content

Commit ede5af0

Browse files
committed
Update prefer-stateless-function documentation
1 parent 37fc544 commit ede5af0

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

docs/rules/prefer-stateless-function.md

+8-18
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ Stateless functional components are more simple than class based components and
66

77
This rule will check your class based React components for
88

9-
* lifecycle methods: `state`, `getInitialState`, `getChildContext`, `componentWillMount`, `componentDidMount`, `componentWillReceiveProps`, `shouldComponentUpdate`, `componentWillUpdate`, `componentDidUpdate` and `componentWillUnmount`
10-
* usage of `this.setState`
9+
* methods/properties other than `displayName`, `propTypes`, `render` and useless constructor (same detection as ESLint [no-useless-constructor rule](http://eslint.org/docs/rules/no-useless-constructor))
10+
* instance property other than `this.props` and `this.context`
11+
* `render` method that return anything but JSX (`undefined`, `null`, etc.)
1112
* presence of `ref` attribute in JSX
1213

13-
If none of these 3 elements are found then the rule warn you to write this component as a pure function.
14+
If none of these 4 elements are found then the rule warn you to write this component as a pure function.
1415

15-
The following patterns are considered warnings:
16+
The following pattern is considered warnings:
1617

1718
```js
1819
var Hello = React.createClass({
@@ -22,17 +23,6 @@ var Hello = React.createClass({
2223
});
2324
```
2425

25-
```js
26-
class Hello extends React.Component {
27-
sayHello() {
28-
alert(`Hello ${this.props.name}`)
29-
}
30-
render() {
31-
return <div onClick={this.sayHello}>Hello {this.props.name}</div>;
32-
}
33-
}
34-
```
35-
3626
The following patterns are not considered warnings:
3727

3828
```js
@@ -43,10 +33,10 @@ const Foo = function(props) {
4333

4434
```js
4535
class Foo extends React.Component {
46-
shouldComponentUpdate() {
47-
return false;
48-
}
4936
render() {
37+
if (!this.props.foo) {
38+
return null
39+
}
5040
return <div>{this.props.foo}</div>;
5141
}
5242
}

0 commit comments

Comments
 (0)