dillon1000/react

Commit

[compiler] Improve setState-in-effects rule to account for ref-gated conditionals (#35147)

Conditionally calling setState in an effect is sometimes necessary, but
should generally follow the pattern of using a "previous vaue" ref to
manually compare and ensure that the setState is idempotent. See fixture
for an example.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/35147).
* #35148
* __->__ #35147
Browse files
Changed paths4 files
First-parent comparison
M compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts ModifiedM compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoSetStateInEffects.ts ModifiedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/valid-setState-in-useEffect-controlled-by-ref-value.expect.md AddedA compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/valid-setState-in-useEffect-controlled-by-ref-value.js Added
Patch

Files changed

Rendering syntax-highlighted changes…