no-redundant-custom-hook
Rule category
Correctness.
What it does
Enforce custom hooks to use at least one other hook inside.
Why is this bad?
If a custom Hook is not calling other Hooks, it might be a sign that it’s unnecessary or incorrectly implemented.
Examples
Failing
import React from 'react';
// @warn: Custom Hooks should use other Hooks.
function useClassnames(obj: Record<string, boolean>) {
var k, cls = "";
for (k in obj) {
if (obj[k]) {
cls && (cls += " ");
cls += k;
}
}
return cls;
};
Passing
import React from 'react';
function useCounter() {
const [count, setCount] = React.useState(0);
const increment = () => setCount(c => c + 1);
return { count, increment };
}