Hook called conditionally
Part of Code Quality & Syntax, which counts for 20% of the overall score. When this check fires it deducts 8 points from that category, once per scan, no matter how many places it turns up.
What it detects
Calling a hook inside an if branch violates the Rules of Hooks: hook order must be identical on every render, and a conditional call changes that order, which corrupts state or crashes with an "order of Hooks changed" error. Heuristic: matches an if that guards a hook call on one line.
Why it matters
Hooks must be called in the same order on every render, so calling one inside an if means the hook is sometimes called and sometimes not. React tracks hooks by call order, so this corrupts the state of later hooks and throws "Rendered fewer hooks than expected" or "order of Hooks changed". This is a heuristic that matches a conditional guarding a hook on one line.
How to fix it
Call the hook unconditionally at the top level of the component, then put the condition inside the hook. For example, always call useEffect and branch inside its callback, or always call useMemo and compute conditionally within it. Never place a hook inside if, for, or a nested function.
The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing
Does your repo trip this check?
Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.
Scan your repo