Skip to content

fix: useSelector usage in logistration and login component - #1203

Merged
syedsajjadkazmii merged 1 commit into
attiya/VAN-1810from
sajjad/VAN-1866
Mar 15, 2024
Merged

fix: useSelector usage in logistration and login component#1203
syedsajjadkazmii merged 1 commit into
attiya/VAN-1810from
sajjad/VAN-1866

Conversation

@syedsajjadkazmii

Copy link
Copy Markdown
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
@codecov

codecov Bot commented Mar 14, 2024

Copy link
Copy Markdown

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 thread src/login/LoginPage.jsx
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
Copy Markdown
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?

@syedsajjadkazmii syedsajjadkazmii Mar 15, 2024

Copy link
Copy Markdown
Contributor Author

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
@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