connected-react-router icon indicating copy to clipboard operation
connected-react-router copied to clipboard

RouterState is missing `match` type

Open bessfernandez opened this issue 5 years ago • 3 comments

Connected React Router exports types for RouterState which is great! However I don't see typings for match. Would assume those could also be part of or be able to be imported into to reducer such as RouterState is used below in examples:

https://github.com/supasate/connected-react-router/blob/master/examples/typescript/src/reducers/index.ts#L13

const rootReducer = (history: History) => combineReducers({
  count: counterReducer,
  router: connectRouter(history)
})

export interface State {
  count: number
  router: RouterState
}

Without which you can't really use this.props.match.params for example in connected components as typings don't exist for match. Is there a workaround here for those using TypeScript? Or am I missing a key part here? Thanks so much!

bessfernandez avatar May 06 '19 21:05 bessfernandez

FWIW I ended up just using match from react-router and passed it in as an additional prop:

import { match } from 'react-router';
/**
 * Additional props for connected React components.
 * This prop is passed by default with `connect()`
 * Note - `match` is provided by React Router and not connected in RouterState,
 * so passed in below as additional prop
 */
export interface ConnectedReduxProps<A extends Action = AnyAction> {
  dispatch: Dispatch<A>;
  match: match<any>;
}

In use:

type AllProps = PropsFromState & PropsFromDispatch & ConnectedReduxProps;
class App extends React.Component<AllProps> { ... }

Would be curious though if folks would still consider this a bug as I would imagine there should still be typings exported from connected-react-router?

bessfernandez avatar May 06 '19 22:05 bessfernandez

Any news regarding this issue? What should be a proper way to inject match prop into a component using connected router?

So far I am using the solution mentioned by @bessfernandez .

jelovac avatar Sep 12 '19 16:09 jelovac

This seems kind of important

br-matt avatar Oct 17 '21 19:10 br-matt