0

I need to pass props inside the Link react Router to another component, but I can't due to the interface or type declarations that I don't understand. I've being searching around and I can't find anything to this problem (Typescript).

Here is the code of my component:

const ImageGallery = () => {

   interface passProps {
      backUrl?: string
   }

   const backUrl = '/some/other/value';

   return (
      <Gallery>
         {images.map((x, i) => (
         <Link key={x} to={{ pathname: 'page', query: { backUrl } }}>
         ...

and here is the error:

(property) backUrl: string
Type '{ pathname: string; query: { backUrl: string; }; }' is not assignable to type 'LocationDescriptor<unknown> | ((location: Location<unknown>) => LocationDescriptor<unknown>)'.
  Object literal may only specify known properties, and 'query' does not exist in type 'LocationDescriptorObject<unknown> | ((location: Location<unknown>) => LocationDescriptor<unknown>)'.ts(2322
karel
  • 5,489
  • 46
  • 45
  • 50

1 Answers1

0

You can add state to <Link> components via a state property.

Previously answered here

Daan Reid
  • 339
  • 2
  • 7