-
-
Notifications
You must be signed in to change notification settings - Fork 705
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
feat(react-router): allow useMatch
to not throw if match was not found
#1738
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit ff43790. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 3 targetsSent with 💌 from NxCloud. |
To me this makes sense, I think I think we just need to think about if |
useMatch
to not throw if match was not founduseMatch
to not throw if match was not found
4d295a9
to
fcfa1ed
Compare
> = StrictOrFrom<TFrom, TStrict> & { | ||
select?: (match: TRouteMatch) => TSelected | ||
shouldThrow?: TThrow |
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 rather this be throw
to match that API surface with what we are already doing with redirect()
.
@@ -62,3 +70,17 @@ function Component() { | |||
// ... | |||
} | |||
``` | |||
|
|||
### checking if a specific route is currently rendered |
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.
Capitalizing the heading.
} from '../src' | ||
import type { RouteComponent, RouterHistory } from '../src' | ||
|
||
describe('useMatch', () => { |
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.
We also probably have a type test in a useMatch.test-d.tsx
, to check for the return type when the throw flag is set to false
vs what it is when true
.
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, for sure we need the type test aswell
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.
Add type tests and I think its all good
fcfa1ed
to
7a16ada
Compare
in this case, `matchRoute` will return undefined
7a16ada
to
ff43790
Compare
in this case,
matchRoute
will return undefined