-
Maintenance
- Upgrade TypeScript to 3.8.3
- Upgrade TSLint to 6.x
-
Allow TSLint 6.x as a
peerDependency
This rule can not be used with TSLint 6.x.
- Fix the description of rule options in README
-
Add support for optionally detecting hook calls from sources other than the
React
namespace (e.g.MyHooks.useHook
).Usage is described in the README.
- Update dependencies due to security vulnerabilities
-
Describe a workaround for ambiguous function expressions in the README
-
Detect and allow using hooks inside named function expressions
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} />; };
-
Report violations whenever a React hook is used after an early return.
For example, the following code sample now violates the rule:
function MyComponent({ counter }) { if (counter > 5) { return <div>Counter is over 5</div>; } useEffect(() => { console.log('Counter is', counter); }); return <div>{counter}</div>; }
-
Allow using hooks inside React component decorators, such as
React.memo
orReact.forwardRef
.For example, the following code sample now does not violate the rule:
const MyComponent = React.memo(props => { useEffect(() => { console.log('Counter changed'); }, [props.value]); return <div>Counter: {props.value}</div>; });
-
Updated README
The source code of the rule did not change. The rule has been released again so that the README on npmjs.com matches the one on GitHub.
- The initial implementation of the rule