Typescript React Component Props Error
Hi, I'm trying to implemented an AuthenticatedRoute component. I'm wrapping the Route component from react-router-dom. Getting a frustrating TS error. I just don't understand how to fix it, can anyone help?
12 Replies
Use composition instead
That way the only prop you need is children
Unknown Userā¢3y ago
Message Not Public
Sign In & Join Server To View
Is there a way to inject the route props at the same time? history, location, match etc.
By that I mean from within the AuthenticatedRoute component add extra props to the Component
probably not
if you want that, i think you'll need to figure out your generic
its going to be hell though
Ahh š¦
tbh either find a library that does this
or prepare to enter generics hell
Would the future āsatisfiesā keyword help here?
you could look at the typedefs for tanstack router and other similar libraries
Sounds good
but its going to be waaaay more complex than what you had going in your op
The generic seems straightforward conceptually. I want ācomponentPropsā to be the same type as the props for the ācomponentā. Strange that itās so hard in practice to do
Unknown Userā¢3y ago
Message Not Public
Sign In & Join Server To View