Skip to content
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

fix: useSelector usage in logistration and login component #1203

Merged
merged 1 commit into from
Mar 15, 2024

Conversation

syedsajjadkazmii
Copy link
Contributor

Description
Optimization PR: This PR enhances the usage of useSelector in the Login and Logistration components, adhering to best practices. By doing so, it reduces unnecessary renders in these components, leading to improved performance.

Docs: Selectors should be as granular as possible
Reference: https://react-redux.js.org/api/hooks

JIRA
VAN-1866

How Has This Been Tested?
Locally

@syedsajjadkazmii syedsajjadkazmii requested a review from a team as a code owner March 14, 2024 18:50
Copy link

codecov bot commented Mar 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.37%. Comparing base (fade402) to head (5bc4942).

Additional details and impacted files
@@                 Coverage Diff                 @@
##           attiya/VAN-1810    #1203      +/-   ##
===================================================
+ Coverage            84.22%   84.37%   +0.14%     
===================================================
  Files                  126      125       -1     
  Lines                 2384     2387       +3     
  Branches               677      677              
===================================================
+ Hits                  2008     2014       +6     
+ Misses                 356      353       -3     
  Partials                20       20              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +49 to +55
const backedUpFormData = useSelector(state => state.login.loginFormData);
const loginErrorCode = useSelector(state => state.login.loginErrorCode);
const loginErrorContext = useSelector(state => state.login.loginErrorContext);
const loginResult = useSelector(state => state.login.loginResult);
const shouldBackupState = useSelector(state => state.login.shouldBackupState);
const showResetPasswordSuccessBanner = useSelector(state => state.login.showResetPasswordSuccessBanner);
const submitState = useSelector(state => state.login.submitState);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you noticed a decrease in rerendering the login component by granular selector state?

Copy link
Contributor Author

@syedsajjadkazmii syedsajjadkazmii Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an extra render of login component which was actually being caused by the re-rendering of its parent component (Logistration).

Logistration was subscribed to register reducer thus a change in register redux state was causing the Logistration hence the Login component to re-render.

By making the useSelectors granular in both components removed that extra render being caused by register store change.

@syedsajjadkazmii syedsajjadkazmii changed the title fix: fix useSelector usage in logistration and login component fix: useSelector usage in logistration and login component Mar 15, 2024
@syedsajjadkazmii syedsajjadkazmii merged commit 82f85ad into attiya/VAN-1810 Mar 15, 2024
7 checks passed
@syedsajjadkazmii syedsajjadkazmii deleted the sajjad/VAN-1866 branch March 15, 2024 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants