react
react copied to clipboard
[compiler] Add enableVerboseNoSetStateInEffect to suggest options to user/agent
The current validateNoSetStateInEffects error has potential false positives because
we cannot fully statically detect patterns where calling setState in an effect is
actually valid. This flag enableVerboseNoSetStateInEffect adds a verbose error mode that presents multiple possible
use-cases, allowing an agent to reason about which fix is appropriate before acting:
- Non-local derived data - suggests restructuring state ownership
- Derived event pattern - suggests requesting an event callback from parent
- Force update / external sync - suggests using
useSyncExternalStore
This gives agents the context needed to make informed decisions rather than blindly applying a fix that may not be correct for the specific situation.