question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WithRouterProps types not available

See original GitHub issue

After upgrading from Next 8.1.0 to 8.1.1 Canary the typescript type definition for WithRouterProps is not there anymore. In the previous version the following statement worked.

import { withRouter, WithRouterProps } from 'next/router';

During the 8.1.1 Canary development iteration withRouter was changed a bit. What is the approach to get those types back again.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
rodogircommented, Jul 16, 2019

@khusamov for now you can do

import { WithRouterProps } from "next/dist/client/with-router";
3reactions
ahutchingscommented, May 20, 2019

I was able to update to use the new typings and wanted to share my solutions:

My component that was being wrapped by withRouter was previously typed with React.FC<WithRouterProps>. I’ve updated its type to be React.FC<{router: PublicRouterInstance}>, where PublicRouterInstance is a type imported from next/router.

I was using LinkProps in the props definition for a component that wrapped Link, and extended the Link interface to accept additional props. My interface was something like interface Props extends LinkProps { ...}. This is now working using interface Props extends React.ComponentPropsWithoutRef<typeof Link> {...}. It’s a little more verbose, so I think there would be some value in exporting a props interface for Link (and other components) to support this pattern.

If there is a better way to achieve these things, I’d be interesting in learning about them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WithRouterProps types not available · Issue #7311 - GitHub
After upgrading from Next 8.1.0 to 8.1.1 Canary the typescript type definition for WithRouterProps is not there anymore.
Read more >
issue with types when using "withRouter" and Typescript
Error arisen from types incompatibility. MenuItem is class, not type. To get type of MenuItem you should use typeof MenuItem .
Read more >
How to use withRouter HOC in React Router v6 with Typescript
Complete guide on how to re-create and use withRouter HOC in React Router v6 with Typescipt.
Read more >
withRouter - React Router: Declarative Routing for React.js
This means that withRouter does not re-render on route transitions unless its parent component re-renders. Static Methods and Properties. All non-react specific ...
Read more >
Handle Props in React in TypeScript
In order to make illegal state unrepresentable, we can split the props into 3 types: enum Mode { easy = 'easy', medium =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found