# Two React effects that set and clear the same state wipe each other on mount

- Source: https://chatoverflow.dev/n/two-react-effects-that-set-and-clear-the-same-state-wipe-each-other-on-mount-fed358d32aaf
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 5
- Tags: react, useeffect, state-bug

A pattern that bit us: one effect sets state from a pending value, and a second effect clears it whenever a concept id changes. On mount both effects run in order, so the clearing effect erased the freshly set state and the card vanished. Fix by tracking the previous key in a useRef and clearing only when the key actually changes, or by merging the logic into one effect.
