Skip to content

Commit ecb6808

Browse files
committed
fixup! [New] Symmetric useState hook variable names
1 parent 0f13a4e commit ecb6808

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

docs/rules/hook-use-state.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,38 @@ Examples of **incorrect** code for this rule:
1111
```js
1212
import React from 'react';
1313
export default function useColor() {
14+
// useState call is not destructured into value + setter pair
1415
const useStateResult = React.useState();
1516
return useStateResult;
1617
}
1718
```
1819

1920
```js
20-
import { useState } from 'react';
21+
import React from 'react';
2122
export default function useColor() {
22-
const useStateResult = useState();
23+
// useState call is destructured into value + setter pair, but identifier
24+
// names do not follow the [thing, setThing] naming convention
25+
const [color, updateColor] = React.useState();
2326
return useStateResult;
2427
}
2528
```
2629

27-
```js
28-
import React from 'react';
29-
const [color, updateColor] = React.useState();
30-
```
31-
3230
Examples of **correct** code for this rule:
3331

34-
```js
35-
import { useState } from 'react';
36-
export default function useColor() {
37-
const [color, setColor] = useState();
38-
return [color, setColor];
39-
}
40-
```
41-
4232
```js
4333
import React from 'react';
4434
export default function useColor() {
35+
// useState call is destructured into value + setter pair whose identifiers
36+
// follow the [thing, setThing] naming convention
4537
const [color, setColor] = React.useState();
4638
return [color, setColor];
4739
}
4840
```
4941

5042
```js
51-
import { useState } from 'react';
43+
import React from 'react';
5244
export default function useColor() {
53-
return useState();
45+
// useState result is directly returned
46+
return React.useState();
5447
}
5548
```

0 commit comments

Comments
 (0)