Code review example: Hallucinated useMount hook: the component fails at build or crashes on first render in React
Retired from the DiffDojo practice pool in October 2026; the review below is the canonical answer. An AI wrote this pull request for the task underneath. Read the diff and decide what you would say before you scroll to the review.
The task
Track window focus for the presence indicator
- Show whether the current tab is focused (green dot when focused, gray when not).
- Subscribe to the window focus/blur events when the component mounts.
- Remove the event listeners when the component unmounts.
Adds the focus tracker for the presence indicator. Subscribes to window focus/blur on mount using React's lifecycle hook and cleans the listeners up on unmount.
Part of the team-presence header shown on every page.
The diff
src/components/FocusIndicator.jsx+18The review
Issue 1: Hallucinated useMount hook: the component fails at build or crashes on first render
- React exports no
useMount. Mount-time work is written withuseEffect(fn, []); the name only feels plausible because userland libraries define auseMounthelper and LLM training data is full of them. - The import can't resolve. With strict ESM linking the build fails on the missing named export; with common CommonJS interop (webpack-style setups) it resolves to
undefinedand the first render throwsTypeError: useMount is not a function. - The body is exactly right, subscribe on mount, cleanup on unmount, but the hook is fictional, so either way the component never works.
The fix: useEffect with an empty dependency array; the returned cleanup handles unmount.
The fix
import { useState, useEffect } from 'react';
export function FocusIndicator() {
const [focused, setFocused] = useState(() => document.hasFocus());
useEffect(() => {
const onFocus = () => setFocused(true);
const onBlur = () => setFocused(false);
window.addEventListener('focus', onFocus);
window.addEventListener('blur', onBlur);
return () => {
window.removeEventListener('focus', onFocus);
window.removeEventListener('blur', onBlur);
};
}, []);
return <span className={focused ? 'dot green' : 'dot gray'} />;
}Why it matters
A hook imported from 'react' that you can't place → ask: "is this React's API or an ecosystem helper?"
Real-world stakes: this is the version-mix flavor of API hallucination, the model blends React's real API with the ecosystem's helper vocabulary (react-use and friends all ship a useMount), producing an import that reads completely natural. The textbook-perfect effect body lowers the reviewer's guard; the whole bug is the import line, and in a webpack-style plain-JS project nothing catches it before the browser throws.
The verdict
Request changes. Hallucinated useMount hook: the component fails at build or crashes on first render
Try a live one
React PRs you have not seen the answer to.
Leave inline comments and a verdict, then see what you caught. Free, no signup.
Review a React PR →