Rules
react-hooks/ensure-custom-hooks-using-other-hooks

react-hooks/ensure-custom-hooks-using-other-hooks

Rule category

Pedantic.

What it does

Helps find 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

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

Passing

const useData = (key) => {
  // Valid, because useData is using other React Hooks.
  return useSWR(key);
};

Further Reading