Documentation
Rules
hooks-extra/ensure-custom-hooks-using-other-hooks

ensure-custom-hooks-using-other-hooks

Rule category

Correctness.

What it does

Warns when custom Hooks that don’t use other Hooks.

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

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 };
}

Further Reading