-
Notifications
You must be signed in to change notification settings - Fork 50k
Open
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bug
Description
This code correctly produces a lint error:
function MyComponent() {
const [loading, setLoading] = useState(false);
useEffect(() => {
setLoading(true); // ✅ ESLint correctly flags this (1 error)
}, []);
// commented out code...
return null;
}But this code does not:
function MyComponent() {
const [loading, setLoading] = useState(false);
useEffect(() => {
setLoading(true); // ❌ BUG: Error no longer reported (should still be flagged!)
}, []);
const [firstName, setFirstName] = useState<string>('');
const [lastName, setLastName] = useState<string>('');
const [fullName, setFullName] = useState<string>('');
useEffect(() => {
setFullName(`${firstName} ${lastName}`); // ❌ BUG: Also not reported
}, [firstName, lastName]);
return null;
}React version: ^19.2.1
Steps To Reproduce
Created a minimal reproduction repo: https://github.com/roryabraham/set-state-in-effect-bug
The current behavior
In the second code snippet provided, no lint errors are thrown.
The expected behavior
Lint errors should be thrown for both setState calls in useEffect callbacks.
SidduKutchula and vbuford26-arch
Metadata
Metadata
Assignees
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bug