Skip to content
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

Using withRouter #16

Open
mayerwin opened this issue Nov 3, 2016 · 2 comments
Open

Using withRouter #16

mayerwin opened this issue Nov 3, 2016 · 2 comments

Comments

@mayerwin
Copy link

mayerwin commented Nov 3, 2016

Are we supposed to use withRouter (recommended with version 2.4+) with TypeScript? If so, how?

@blakeembrey
Copy link
Member

blakeembrey commented Nov 14, 2016

It doesn't seem anyone is actively maintaining this repo right now. If you're interested and you'd like to help out, I can add you as a maintainer. And/or someone from @types can add an additional comment and/or help you.

@guilhermehubner
Copy link

I've found a way to solve this problem as you can see below:

type OwnProps = RouteComponentProps<{id: number}>;

const mapStateToProps = (state: GlobalStateType, ownProps: OwnProps): StateToPropsType => ({
        id: ownProps.match.params.id
});

type PropsType = StateToPropsType & DispathToPropsType & OwnProps;

class MyPage extends React.Component<PropsType, StateType> {
   ...
}

const mapDispatchToProps = (dispatch: DispatchType): DispathToPropsType => ({
    ...
});

export default withRouter(connect<StateToPropsType, DispathToPropsType, OwnProps> (
    mapStateToProps,
    mapDispatchToProps
)(MyPage));

In router:

<Provider store={store}>
   <BrowserRouter>
      <Switch>
         <Route path="/:id(\d+)" component={MyPage} />
      <Switch>
  <BrowserRouter>
</Provider>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants