react-hooks/ensure-custom-hooks-using-other-hooks
Rule category
Pedantic.
What it does
Helps find custom Hooks that don't use other Hooks.
:warning: This rule is in early-access! Please report any bugs or feedback on the issue tracker (opens in a new tab)
Why is this good?
Custom Hooks may call other Hooks (that’s their whole purpose). If a custom Hook is not calling other Hooks, it might be a sign that it's unnecessary or incorrectly implemented. This rule helps you catch those cases.
Examples
❌ Incorrect
const useClassnames = (obj) => {
// Invalid, because useClassnames doesn't use any other React Hooks.
var k, cls = "";
for (k in obj) {
if (obj[k]) {
cls && (cls += " ");
cls += k;
}
}
return cls;
};
✅ Correct
const useData = (key) => {
// Valid, because useData is using other React Hooks.
return useSWR(key);
};