Skip to content

Commit

Permalink
fixup! [New] Symmetric useState hook variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanbeevers committed Nov 26, 2021
1 parent 0f13a4e commit ecb6808
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions docs/rules/hook-use-state.md
Expand Up @@ -11,45 +11,38 @@ Examples of **incorrect** code for this rule:
```js
import React from 'react';
export default function useColor() {
// useState call is not destructured into value + setter pair
const useStateResult = React.useState();
return useStateResult;
}
```

```js
import { useState } from 'react';
import React from 'react';
export default function useColor() {
const useStateResult = useState();
// useState call is destructured into value + setter pair, but identifier
// names do not follow the [thing, setThing] naming convention
const [color, updateColor] = React.useState();
return useStateResult;
}
```

```js
import React from 'react';
const [color, updateColor] = React.useState();
```

Examples of **correct** code for this rule:

```js
import { useState } from 'react';
export default function useColor() {
const [color, setColor] = useState();
return [color, setColor];
}
```

```js
import React from 'react';
export default function useColor() {
// useState call is destructured into value + setter pair whose identifiers
// follow the [thing, setThing] naming convention
const [color, setColor] = React.useState();
return [color, setColor];
}
```

```js
import { useState } from 'react';
import React from 'react';
export default function useColor() {
return useState();
// useState result is directly returned
return React.useState();
}
```

0 comments on commit ecb6808

Please sign in to comment.