[Enhancement] Add useMemo and useCallback to useSnackbar Hook #617
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.
Description of Change
Added memoization to the
useSnackbar
hook by utilizinguseCallback
anduseMemo
. This prevents the snackbar from being re-rendered when utilized inside auseEffect
hook by the caller, which could have the undesirable effect of leaving the snackbar visible when it was intended to be hidden.Testing Packages
Screenshots/Video
These before/after videos show the issue in the VA Mobile app. Notice how in the 'Before' video the snackbar does not correctly get dismissed when backing up a screen.
Snackbar.Before.mp4
Snackbar.After.mp4
Testing
Testing was performed in the VA Mobile app using this branch which has yet to be deployed. In order to force the Snackbar to appear, the downloadDecisionLetter function was temporarily modified to throw an exception. After clicking on a claim letter, the Snackbar will appear. When navigating back a screen the Snackbar should disappear, but it does not without the memoization fix in this PR.
PR Checklist
Code reviewer validation:
changelog
label applied if it's to be included in the changelogPublish
If changes warrant a new version per the versioning guidelines and the PR is approved and ready to merge:
main
into branchmain