-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ML] Improvements for urlState hook. #70576
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
239f510
[ML] Fix/improve url state.
walterra 06b0235
[ML] Renames for clarity.
walterra 9c9686a
[ML] More renames.
walterra 4bbf4f0
Merge branch 'master' into ml-improve-url-state
walterra 4b43b48
[ML] Adjust tests.
walterra 3500f11
[ML] Enforce to use only accessor default value. More comments.
walterra 1b7eda2
Merge branch 'master' into ml-improve-url-state
elasticmachine 9993a13
[ML] Use context to have only one instance of url state.
walterra 1e8514b
[ML] Fix TS and unit tests.
walterra 60911c3
[ML] Reduce rerenders.
walterra a80e5c8
Merge branch 'master' into ml-improve-url-state
walterra 53d20e6
[ML] Update tests to include UrlStateProvider.
walterra 33fed07
Merge branch 'master' into ml-improve-url-state
walterra a4933fe
Merge branch 'master' into ml-improve-url-state
elasticmachine d39d470
Merge branch 'master' into ml-improve-url-state
elasticmachine ad2788f
Merge branch 'master' into ml-improve-url-state
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
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.
I'd suggest storing the result of
getUrlState
in some state value or observable and update it based on URL changes. It will let use to avoid retrieving the value from URL string on each render.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.
Maybe the naming was just not as obvious, but that PR already does that:
locationSearch
refers to what we get from React Router'suseLocation
,search
is the state value we keep.getUrlState()
is a pure function that just parses the search string so we can compare the namespace/accessor (_g
/_a
), it's not touching the URL directly.I pushed some more commits with renames to make this more obvious:
getUrlState
toparseUrlState
locationSearch
tolocationSearchString
search
tosearchString
Also added a
useMemo
at the end of the hook so we return a memoized version of the parsed url state.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.
yes, this commit 06b0235 introduced
useMemo
with a parsed object, this is what I meant 👍