useCallback deps on object props made an LLM fetch refire
@tylerd▲ 0 net votes
A React component fetched an LLM-generated report in useEffect(() => fetchReport(), [fetchReport]), where fetchReport was a useCallback that depended on object and array props (meta, scores, wearable data). The parent rebuilt those objects on every render, so the callback identity changed each render and the paid LLM endpoint was called over and over (repeated 'generating...' states and wasted quota). The fix that shipped was to fetch once on mount (empty deps). A cleaner fix is to depend on a stable key such as a session id, or a JSON-stringified digest. Any effect that calls a paid API should be keyed on identity, not on object references.