This repository has been archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Make password creation form functional #102
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jacque006
approved these changes
Jan 18, 2022
Comment on lines
+47
to
+57
const confirmFieldClasses = ['password-confirm-field']; | ||
|
||
if (confirmPasswordFieldValue === '') { | ||
confirmFieldClasses.push('empty'); | ||
} else if (confirmPasswordFieldValue === passwordFieldValue) { | ||
confirmFieldClasses.push('correct'); | ||
} else if (passwordFieldValue.startsWith(confirmPasswordFieldValue)) { | ||
confirmFieldClasses.push('incomplete'); | ||
} else { | ||
confirmFieldClasses.push('incorrect'); | ||
} |
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.
To prevent redundant computation in render cycles and prevent subcomponents from unnecessarily re-rendering, generating values like this can be memoized. https://reactjs.org/docs/hooks-reference.html#usememo
Suggested change
const confirmFieldClasses = ['password-confirm-field']; | |
if (confirmPasswordFieldValue === '') { | |
confirmFieldClasses.push('empty'); | |
} else if (confirmPasswordFieldValue === passwordFieldValue) { | |
confirmFieldClasses.push('correct'); | |
} else if (passwordFieldValue.startsWith(confirmPasswordFieldValue)) { | |
confirmFieldClasses.push('incomplete'); | |
} else { | |
confirmFieldClasses.push('incorrect'); | |
} | |
const confirmFieldClasses = React.useMemo(() => { | |
const classes = ['password-confirm-field']; | |
if (confirmPasswordFieldValue === '') { | |
classes.push('empty'); | |
} else if (confirmPasswordFieldValue === passwordFieldValue) { | |
classes.push('correct'); | |
} else if (passwordFieldValue.startsWith(confirmPasswordFieldValue)) { | |
classes.push('incomplete'); | |
} else { | |
classes.push('incorrect'); | |
} | |
return classes; | |
}, [confirmPasswordFieldValue, passwordFieldValue]); |
Now confirmFieldClasses
will only become a new Array
object when either confirmPasswordFieldValue
or passwordFieldValue
changes.
I don't think this is needed for this round of changes, but something to keep in mind.
2 tasks
This was merged before #95. Oops. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Dependent PR
This PR builds on top of #95. Please review and merge that one first.
What is this PR doing?
Adds functionality to the password creation form:
I included some naive css this time because I couldn't help it. Just things like
background-color: green
though. Intended to be thrown away.How can these changes be manually tested?
Visit the password creation form and verify the above.
Does this PR resolve or contribute to any issues?
Resolves #97, resolves #98.
Checklist
Guidelines
resolve conversation
button is for reviewers, not authors