-
-
Notifications
You must be signed in to change notification settings - Fork 10.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
🗺 Pass a bag of props to Component
#9885
Comments
What can I do to move this forward? Are you open to PRs that implement this specifically? |
Do we still need this now that we're moving towards |
Based on what I see in the linked PR, I don't see a way to do something like <Route path='/user/:userId' element={({userid}) => <UserProfile id={userid} />} /> that would have TypenScript error with |
Initially implemented by #10045 with |
element
prop with a function that receives router context valuesComponent
@ryanflorence If there is interest in something like this, I'm happy to provide a PR once #10045 is merged which either passes the params, or a bigger object containing the params to the component. Here's how I imagine the interface towards users of the library: function UserProfile({userId}: {userId: string}) {
return <>You are user {userId}</>
}
// This just works
<Route path='/user/:userId' Component={UserProfile} />
// This gives a TypeScript Error:
// Type '({ userId }: { userId: string; }) => Element' is not assignable to type 'ComponentType<{ userid: string; }>'.
// Type '({ userId }: { userId: string; }) => Element' is not assignable to type 'FunctionComponent<{ userid: string; }>'.
// Types of parameters '__0' and 'props' are incompatible.
// Property 'userId' is missing in type '{ userid: string; }' but required in type '{ userId: string; }'
<Route path='/user/:userid' Component={UserProfile} /> |
I love this @dbartholomae! I personally can't think of any reason why we would need other functionalities than the URL params and the integration with the components and their props would be amazing. Being able to pass a component as prop rather than a function might also be better for re-renderings since its reference wouldn't change. |
Discussed in #9687
match
but other stuff likenavigate
,location
etc. (hash out what comes in there with the RFC)The text was updated successfully, but these errors were encountered: