Fix the 17 react-hooks/set-state-in-effect lint errors #78
Labels
No labels
bug
chore
data
feature
frontend
good first issue
intermediate
needs/docs
needs/research
needs/upstream
type/bug
type/external
type/feature
type/refactor
urgency
high
urgency
immediate
urgency
low
urgency
medium
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ScottyLabs/cal#78
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What's wrong
npx eslint .inweb/reports 17react-hooks/set-state-in-effecterrors. Each one callssetStatedirectly insideuseEffect, which renders twice and can show stale or flickering UI. They fall into three kinds.How to reproduce
cd web && npx eslint .react-hooks/set-state-in-effectin the output.Expected
Zero errors from this rule, with no change in behavior.
Where to look
EventPopover.tsx(tags),ModalEvent.tsx(2),ManagerSidebar.tsx,ProfileSidebar.tsx,ManagerDashboard.tsx(reset on org change),UserContext.tsx(fetchEvents). Fix: set the flag in the handler that starts the fetch, derive "loading" from data that is not there yet, or remount withkeywhen the id changes.EventPopover.tsx(savedEventDetails),ManagerDashboard.tsx(two dialogs),ModalEventUpdate.tsx,ModalEventForm.tsx,SearchResultSidebar.tsx(3:filteredByTags, the tag effect, page reset). Fix: compute it during render if it is never edited; if it is edited, give the componentkey={id}so state starts from props; reset the page in the filteronChangehandlers.Navbar.tsx,SignedOutNav.tsx. Fix: a smalluseMounted()hook built onuseSyncExternalStore(subscribe, () => true, () => false).Done when
npx eslint .shows noset-state-in-effecterrors.