Skip to content

Commit dfa5005

Browse files
committed
Add more documentation for no-this-in-sfc
1 parent 80fb96c commit dfa5005

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

docs/rules/no-this-in-sfc.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ function Foo(props) {
1717
}
1818
```
1919

20+
```jsx
21+
function Foo(props) {
22+
const { bar } = this.props;
23+
return (
24+
<div>{bar}</div>
25+
);
26+
}
27+
```
28+
2029
```jsx
2130
function Foo(props, context) {
2231
return (
@@ -27,6 +36,18 @@ function Foo(props, context) {
2736
}
2837
```
2938

39+
```jsx
40+
function Foo(props, context) {
41+
const { foo } = this.context;
42+
const { bar } = this.props;
43+
return (
44+
<div>
45+
{foo ? bar : ''}
46+
</div>
47+
);
48+
}
49+
```
50+
3051
```jsx
3152
function Foo(props) {
3253
if (this.state.loading) {
@@ -40,6 +61,21 @@ function Foo(props) {
4061
}
4162
```
4263

64+
```jsx
65+
function Foo(props) {
66+
const { loading } = this.state;
67+
const { bar } = this.props;
68+
if (loading) {
69+
return <Loader />;
70+
}
71+
return (
72+
<div>
73+
{bar}
74+
</div>
75+
);
76+
}
77+
```
78+
4379
The following patterns are **not** considered warnings:
4480

4581
```jsx
@@ -50,6 +86,23 @@ function Foo(props) {
5086
}
5187
```
5288

89+
```jsx
90+
function Foo(props) {
91+
const { bar } = props;
92+
return (
93+
<div>{bar}</div>
94+
);
95+
}
96+
```
97+
98+
```jsx
99+
function Foo({ bar }) {
100+
return (
101+
<div>{bar}</div>
102+
);
103+
}
104+
```
105+
53106
```jsx
54107
function Foo(props, context) {
55108
return (
@@ -59,3 +112,25 @@ function Foo(props, context) {
59112
);
60113
}
61114
```
115+
116+
```jsx
117+
function Foo(props, context) {
118+
const { foo } = context;
119+
const { bar } = props;
120+
return (
121+
<div>
122+
{foo ? bar : ''}
123+
</div>
124+
);
125+
}
126+
```
127+
128+
```jsx
129+
function Foo({ bar }, { foo }) {
130+
return (
131+
<div>
132+
{foo ? bar : ''}
133+
</div>
134+
);
135+
}
136+
```

0 commit comments

Comments
 (0)