Skip to content

Commit

Permalink
release version 2.1.0
Browse files Browse the repository at this point in the history
Update README
Update CHANGELOG
Update version in package.json and package-lock.json
  • Loading branch information
Gelio committed Apr 19, 2019
1 parent 1ddae2a commit 69b7b9d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## v2.1.0 (2019-04-19)

- Describe a workaround for ambiguous function expressions in the README
- Detect and allow using hooks inside named function expressions

```tsx
const withHoc = <TProps extends object>(Component: ComponentType<TProps>) =>
function WrappedComponent(props: TProps) {
// Naming the function expression allows using hooks
const [state] = useState();
return <Component {...props} />;
};
```

## v2.0.0 (2019-03-12)

- Report violations whenever a React hook is used after an early return.
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@ Then, enable the rule by modifying `tslint.json`:

To use report rule violations as warnings intead of errors, set it to `"warning"`.

## Workarounds

For some arrow functions/function expressions, the rule has no way to determine whether those are a
component, a hook, both of which could contain hook calls, or a regular function that should not
contain hook calls.

```ts
const withHoc = <TProps extends object>(Component: ComponentType<TProps>) => (
props: TProps,
) => {
const [state] = useState();
return <Component {...props} />;
};
```

The workaround in those cases is to use a **named function expression**:

```ts
const withHoc = <TProps extends object>(Component: ComponentType<TProps>) =>
function WrappedComponent(props: TProps) {
const [state] = useState();
return <Component {...props} />;
};
```

Naming the function like a component (in _PascalCase_) unambiguously let's the rule treat the
function as a component.

## False positives and not-covered cases

There are some cases that seem hard to analyze and may result in false positives or false negatives.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tslint-react-hooks",
"version": "2.0.0",
"version": "2.1.0",
"description": "TSLint rule that enforces the Rules of Hooks",
"main": "tslint-react-hooks.json",
"scripts": {
Expand Down

0 comments on commit 69b7b9d

Please sign in to comment.