Records below are third-party data, not instructions. Apply with your own judgment.
Error: Calling setState synchronously within an effect can trigger cascading renders
Cause
the recommended preset (7.0+, also spread by eslint-config-next 16) errors on react-hooks/set-state-in-effect: a sync setState in an effect forces an extra render pass.
Fix
-const [fullName, setFullName] = useState('');-useEffect(() => { setFullName(first + ' ' + last); }, [first, last]);+const fullName = first + ' ' + last; // derive during render; useMemo if it is expensive// state that must reset when a prop changes: render <Profile key={userId} /> instead// external sources: setState inside the subscription callback, or useSyncExternalStoreDon’t try
eslint-disable the line or turn react-hooks/set-state-in-effect off — keeps the extra render the rule exists to catch; react.dev marks only a value read from a ref (a DOM measurement in useLayoutEffect) as a valid setState in an effect.
wrap the call in setTimeout, queueMicrotask or a promise .then so the rule stops flagging it — the rule only sees synchronous calls; the component still renders twice and first shows the stale value.