SIGN IN SIGN UP

[compiler] Add enableUseKeyedState flag and improve setState-in-render errors (#35230)

Adds a new `enableUseKeyedState` compiler flag that changes the error
message for unconditional setState calls during render.

When `enableUseKeyedState` is enabled, the error recommends using
`useKeyedState(initialState, key)` to reset state when dependencies
change. When disabled (the default), it links to the React docs for the
manual pattern of storing previous values in state.

Both error messages now include helpful bullet points explaining the two
main alternatives:
1. Use useKeyedState (or manual pattern) to reset state when other
state/props change
2. Compute derived data directly during render without using state
L
lauren committed
f99241b2e6cec825dfbdbb878755f12e1f510ca9
Parent: 66ae640
Committed by GitHub <noreply@github.com> on 12/4/2025, 11:29:10 PM