-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
no-use-state-initializer-functions rule #138
no-use-state-initializer-functions rule #138
Conversation
All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
@mountiny, this PR is ready for review 🙂 |
@alitoshmatov Can you please test this PR and review it? thanks! |
@rezkiy37 I think we should also cover a case where |
@alitoshmatov, done - fa4c5fd. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! lets get this in App now 🚀
…l expressions with function calls
fb1f439
to
9420237
Compare
I've pushed commits forcefully to sign them. |
This PR implements a new ESLint rule to detect and restricts usage initializer functions for useState in E/App. Basically, when a function is being called directly within the useState hook, which means it gets executed on every render, even though it only needs to run during the initial state setup.
We can pass a callback to the useState hook instead. This ensures the function is only executed once during the initial render, improving performance:
By making this change, e.g. BottomTabBar avoids unnecessary re-execution of
getChatTabBrickRoad
on every render. This optimization reduces the render time from approximately±500ms
to just50-100ms
, resulting in a more than 5x performance improvement (Expensify/App#53201). This ESLint rule detects these situations to avoid such perf. problems like Expensify/App#53162.Issue: Expensify/App#53322, Expensify/App#53162
Tests
eslint-config-expensify
repo to E/App:npx link publish <path-to-eslint-repo>/
.src/components/TimePicker/TimePicker.tsx
, and commit that file.npm run lint-changed
, assert the errors were reported.Screenshots