←PR REVIEWStale Closure in useCallback#712AirbnbPalantir
⏱ 00:00Mid~12 min
PULL REQUEST
Open#712 · 1 commit
Stale Closure in useCallback
mid-dev-44 wants to mergefix/autosave-stale-data→main
MI
mid-dev-44
1 file changed · 2 hours ago
YOUR MISSION
A dev is using a debounced "Auto-Save" feature in a text editor. Users report that when they type "Hello World", the database often only saves "H" or nothing at all, despite the UI showing the full text.
Mid~12 min
HINTS (0/3 used)
REVIEWING AS
SR
Senior Engineer
@ Airbnb · Backend Platform
src / components / Editor.tsx+1−1
8
8
const [text, setText] = useState("");
9
9
10
10
const saveToServer = useCallback(
11
11
debounce(() => {
12
12
console.log("Saving:", text);
13
13
api.save(text);
14
14
}, 1000),
15
15
−
[]
+
15
+
[] // Empty deps to "prevent unnecessary re-renders"
+
16
16
);
Click any changed line (+/−) to flag an issue · or Approve if everything looks safe