Skip to content

Commit

Permalink
docs: Added the rules for hooks_avoid_within_class.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikaera authored Mar 4, 2024
1 parent 9e24f8d commit 27e7757
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The currently available lint rules are as follows:
| LintRule | Description | Quickfix |
| ------------- | ------------- | ------------- |
| [hooks_avoid_nesting](#hooks_avoid_nesting) | You should use Hooks only inside the build method of a Widget. | |
| [hooks_avoid_within_class](#hooks_avoid_within_class) | Hooks must not be defined within the class. | |
| [hooks_name_convention](#hooks_name_convention) | DO always prefix your hooks with use, https://pub.dev/packages/flutter_hooks#rules. | |
| [hooks_extends](#hooks_extends) | Using Hooks inside a Widget other than HookWidget or HookConsumerWidget will result in an error at runtime. ||
| [hooks_unuse_widget](#hooks_unuse_widget) | If you are not using Hooks inside of a Widget, you do not need HookWidget or HookConsumerWidget. ||
Expand Down Expand Up @@ -118,6 +119,30 @@ Widget build(BuildContext context) {
}
```

### hooks_avoid_within_class

Defining Custom Hooks within a class mixes the characteristics of class and method, leading to potentially complex code.

**Bad**

```dart
class TestHelper {
const TestHelper._();
static void useEffectOnce(Dispose? Function() effect) { // ❌
useEffect(effect, const []);
}
}
```

**Good**:

```dart
void useEffectOnce(Dispose? Function() effect) { // ⭕
useEffect(effect, const []);
}
```

### hooks_name_convention

**DO always prefix your hooks with use.**
Expand Down

0 comments on commit 27e7757

Please sign in to comment.