-
Notifications
You must be signed in to change notification settings - Fork 194
Tanstack React Router: add useMatches function #2882
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
Open
Dominick Johnson (dmjohnsson23)
wants to merge
1
commit into
JetBrains:master
Choose a base branch
from
dmjohnsson23:breadcrumbs-react
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+47
−0
Open
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions
11
kotlin-tanstack-react-router/src/jsMain/kotlin/tanstack/react/router/UseMatchesOptions.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package tanstack.react.router | ||
|
|
||
| import kotlinx.js.JsPlainObject | ||
| import js.array.ReadonlyArray | ||
|
|
||
| @JsPlainObject | ||
| internal /* raw */ | ||
| external interface UseMatchesOptions<T> { | ||
| val select: Select<ReadonlyArray<RouteMatch>, T>? | ||
| val structuralSharing: Boolean? | ||
| } |
17 changes: 17 additions & 0 deletions
17
kotlin-tanstack-react-router/src/jsMain/kotlin/tanstack/react/router/useMatches.ext.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package tanstack.react.router | ||
|
|
||
| import js.array.ReadonlyArray | ||
|
|
||
| fun useMatches(): ReadonlyArray<RouteMatch> = | ||
| useMatches(UseMatchesOptions()) | ||
|
|
||
| fun <T> useMatches( | ||
| select: Select<ReadonlyArray<RouteMatch>, T>, | ||
| ): T = | ||
| useMatches(UseMatchesOptions(select = select)) | ||
|
|
||
| fun <T> useMatches( | ||
| select: Select<ReadonlyArray<RouteMatch>, T>, | ||
| structuralSharing: Boolean, | ||
| ): T = | ||
| useMatches(UseMatchesOptions(select = select, structuralSharing = structuralSharing)) | ||
19 changes: 19 additions & 0 deletions
19
kotlin-tanstack-react-router/src/jsMain/kotlin/tanstack/react/router/useMatches.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| @file:JsModule("@tanstack/react-router") | ||
|
|
||
| package tanstack.react.router | ||
|
|
||
| /** | ||
| * The useMatches hook returns the router's complete presented array of RouteMatch objects regardless of its caller's position in the component tree. The array can include still-loading descendants or matches below a pending/error/not-found render boundary. | ||
| * | ||
| * Options: | ||
| * - `select`: If supplied, this function will be called with the route matches and the return value will be returned from useMatches. This value will also be used to determine if the hook should re-render its parent component using shallow equality checks. | ||
| * - `structuralSharing`: Configures whether structural sharing is enabled for the value returned by select. | ||
| * | ||
| * [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook) | ||
| * | ||
| * @return An array of RouteMatch objects (or selected value) for the matched route. | ||
| */ | ||
| internal /* raw */ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed overload without parameters? |
||
| external fun <T> useMatches( | ||
| options: UseMatchesOptions<T>, | ||
| ): T | ||
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.
Do we need this overload?