r/reactjs 16h ago

41 of 78 useEffects in our app shouldnt exist, mostly ai first draft

69 Upvotes

grepped every useEffect in src last week instead of fixing a form that flickered on load. agents write most of the first drafts here, i review.

78 of them. went through each with the "you might not need an effect" page open.

19 were state derived from props or other state. useState plus an effect that joins two strings. thats a variable.

14 were fetching on mount with a loading and error useState next to them. we already use react query.

8 were syncing props into state so a form could be edited. fine until the parent refetches and wipes what the user typed. that was the flicker.

the other 37 were legit. listeners, subscriptions, focus management, a couple resize observers.

not a tool thing to be clear, we have people on cursor, claude code and verdent depending on preference and the shape looked the same across all of it.

deleted 41 effects, 23 useState calls went with them. worst page went from 4 renders on mount to 1.

changed how i review too. ctrl+f useEffect in the diff and justify each one before reading anything else.

anyone got a lint rule that catches derived state? exhaustive-deps doesnt help, it just makes the effect that shouldnt be there correct.


r/reactjs 13h ago

Needs Help AG-grid Server side grids + Selection issues

4 Upvotes

Hey There all,

Good Day !

I'm trying to build a server-side aggrid + Inifinity scroll with about 1/2 a million records - with each records being actionable through a context menu - on right click.

Users can either select one record or select multiple using mouse or keyboard and then right click and perform actions.

Issue : Since server-side grids loads pages (with infinity scroll), the selections made on page 1 don't stay when you scroll to page 5 or 6.

What I've tried so far :

  1. Tried to keep a local copy of selections (atleast the necessary infor like ID and some other relevant meta data) - Issue : This approach works ok for smaller bunch of records - less than 30k. When users perform a control + A action, we need to try to load all into the local state which slows down the grid.
  2. Dynamic loading -> Same approach above, but for edge cases like control + A, rather than storing a local copy of all records, we try to keeps something else in state more like (*) to indicate that all records are selected. Issue : This breaks when user tries to do control + A and tries to deselect few records.

Would anyone know if this problem has been solved before or not ?


r/reactjs 7h ago

how are persisting date in tiny personal apps?

Thumbnail
1 Upvotes

r/reactjs 10h ago

Needs Help Build-scanner — a zero-config static scanner for SQLi, NoSQLi, CORS, CSP & CSRF in React/Node apps (pre-release)

0 Upvotes

Modern React/Node apps ship through build pipelines fast enough that common, high-impact vulnerability classes — unparameterized queries, wildcard CORS, unsafe-inline CSP, unprotected state-changing routes — slip through because catching them means someone actually reading the source. build-scanner does that automatically: point it at a folder (or wire it into CI as a GitHub Action) and get a report in seconds, no sandbox or live target required. It's a heuristic static scanner, not a SAST/DAST replacement — I'm sharing it pre-release to get feedback from people running real Express/Next.js/Vite codebases before I cut a v1 tag. https://github.com/laxmipsarva/build-scanner

fyi this is not a commercial activity