SIGN IN SIGN UP
facebook / react UNCLAIMED

The library for web and native user interfaces.

0 0 0 JavaScript

[compiler] Add enableUseKeyedState flag and improve setState-in-render errors

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 Tan committed
b2533549868b8377d74981fb2a673f53459de7b1
Parent: 66ae640