Skip to content

Commit 87fb344

Browse files
maurer2ljharb
authored andcommitted
[Docs] sort-comp: add class component examples
1 parent bdbd2a4 commit 87fb344

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2020
* [Refactor] [`jsx-indent-props`]: improved readability of the checkNodesIndent function ([#3315][] @caroline223)
2121
* [Tests] [`jsx-indent`], [`jsx-one-expression-per-line`]: add passing test cases ([#3314][] @ROSSROSALES)
2222
* [Refactor] `boolean-prop-naming`, `jsx-indent`: avoid assigning to arguments ([#3316][] @caroline223)
23+
* [Docs] `sort-comp`: add class component examples ([#3339][] @maurer2)
2324

25+
[#3339]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3339
2426
[#3331]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3331
2527
[#3328]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3328
2628
[#3327]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3327

docs/rules/sort-comp.md

+60
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ var Hello = createReactClass({
2424
});
2525
```
2626

27+
```jsx
28+
class Hello extends React.Component {
29+
render() {
30+
return <div>Hello</div>;
31+
}
32+
static displayName = 'Hello';
33+
}
34+
```
35+
2736
Examples of **correct** code for this rule:
2837

2938
```jsx
@@ -35,6 +44,15 @@ var Hello = createReactClass({
3544
});
3645
```
3746

47+
```jsx
48+
class Hello extends React.Component {
49+
static displayName = 'Hello';
50+
render() {
51+
return <div>Hello</div>;
52+
}
53+
}
54+
```
55+
3856
## Rule Options
3957

4058
This rule can take one argument to customize the components organisation.
@@ -128,6 +146,16 @@ var Hello = createReactClass({
128146
});
129147
```
130148

149+
```jsx
150+
class Hello extends React.Component {
151+
render() {
152+
return <div>Hello</div>;
153+
}
154+
onClick = this.onClick.bind(this);
155+
onClick() {}
156+
}
157+
```
158+
131159
Examples of **correct** code for this rule, with the above configuration:
132160

133161
```jsx
@@ -139,6 +167,16 @@ var Hello = createReactClass({
139167
});
140168
```
141169

170+
```jsx
171+
class Hello extends React.Component {
172+
onClick = this.onClick.bind(this);
173+
onClick() {}
174+
render() {
175+
return <div>Hello</div>;
176+
}
177+
}
178+
```
179+
142180
If you want to split your `render` method into smaller ones and keep them just before render:
143181

144182
```js
@@ -170,6 +208,17 @@ var Hello = createReactClass({
170208
});
171209
```
172210

211+
```jsx
212+
class Hello extends React.Component {
213+
renderButton = () => {}
214+
onClick = this.onClick.bind(this);
215+
onClick() {}
216+
render() {
217+
return <div>Hello</div>;
218+
}
219+
}
220+
```
221+
173222
Examples of **correct** code for this rule, with the above configuration:
174223

175224
```jsx
@@ -182,6 +231,17 @@ var Hello = createReactClass({
182231
});
183232
```
184233

234+
```jsx
235+
class Hello extends React.Component {
236+
onClick = this.onClick.bind(this);
237+
onClick() {}
238+
renderButton = () => {}
239+
render() {
240+
return <div>Hello</div>;
241+
}
242+
}
243+
```
244+
185245
If you want to flow annotations to be at the top:
186246

187247
```js

0 commit comments

Comments
 (0)