The first rule of Hooks is to only call hooks at the top level, i.e. "Don’t call Hooks inside loops, conditions, or nested functions". The docs explains pretty clearly with an example for calling Hooks inside conditions, but not for the other two cases: loops and nested functions.
Are there examples where something can go wrong when calling Hooks inside loops and nested functions? Moreover, isn't a custom hook just a nested function?
The provided answers for these two related questions here and here unfortunately only give the correct examples.