2

I have the following JSX code -

export default function AppliedRoute({ component: C, appProps, ...rest }) {
    <Route {...rest} render={props => <C {...props} {...appProps} />} />
  return <Route {...rest} render={props => <C {...props} {...appProps} />} />;
}

I want to convert this to typescript, and need to set the component that is being passed in and set as the route component (i.e. via component: C) to a type but cant figure out the syntax for this. If it was just the destructured component object property I could use {component}: {component:any}, appProps.. etc but I dont know the proper syntax when the property is being set to another property for use in the route component call. I would assume the property C would also need a type?

Thank You.

BrokenWings
  • 169
  • 12
  • You should first add a type to the component AppliedRoute itself. Then add the props as an interface. Read more here: https://fettblog.eu/typescript-react/components/ – Remi Nov 19 '19 at 10:58

0 Answers0