mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Type and export props from withRouter
In react-router v3.0.5, [`withRouter`][0] passes 4 props to the wrapped component: `location`, `params`, `router`, and `routes`. These props are different than those passed to `Route` components; these all come directly from the Router either via `this.props` or `this.context`. The component passed to `withRouter` are passed these props, but the component returned from `withRouter` require only the component's own props. [0]: https://github.com/ReactTraining/react-router/blob/v3.0.5/modules/withRouter.js#L40
This commit is contained in:
Vendored
+1
@@ -13,6 +13,7 @@
|
||||
// Huy Nguyen <https://github.com/huy-nguyen>
|
||||
// Jérémy Fauvel <https://github.com/grmiade>
|
||||
// Daniel Roth <https://github.com/DaIgeb>
|
||||
// Ross Allen <https://github.com/ssorallen>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
|
||||
Vendored
+1
@@ -34,6 +34,7 @@ export { RouteProps, PlainRoute } from "react-router/lib/Route";
|
||||
export { IndexRouteProps } from "react-router/lib/IndexRoute";
|
||||
export { RedirectProps } from "react-router/lib/Redirect";
|
||||
export { IndexRedirectProps } from "react-router/lib/IndexRedirect";
|
||||
export { WithRouterProps } from "react-router/lib/withRouter";
|
||||
|
||||
/* components */
|
||||
export { default as Router } from "react-router/lib/Router";
|
||||
|
||||
+12
-2
@@ -1,12 +1,22 @@
|
||||
import { ComponentClass, StatelessComponent } from "react";
|
||||
import { InjectedRouter, Params } from "./Router";
|
||||
import { Location } from "history";
|
||||
import { PlainRoute } from "./Route";
|
||||
|
||||
interface Options {
|
||||
withRef?: boolean;
|
||||
}
|
||||
|
||||
export interface WithRouterProps {
|
||||
location: Location;
|
||||
params: Params;
|
||||
router: InjectedRouter;
|
||||
routes: PlainRoute[];
|
||||
}
|
||||
|
||||
type ComponentConstructor<P> = ComponentClass<P> | StatelessComponent<P>;
|
||||
|
||||
declare function withRouter<P, S>(component: ComponentConstructor<P> & S, options?: Options): ComponentClass<P> & S;
|
||||
declare function withRouter<P>(component: ComponentConstructor<P>, options?: Options): ComponentClass<P>;
|
||||
declare function withRouter<P, S>(component: ComponentConstructor<P & WithRouterProps> & S, options?: Options): ComponentClass<P> & S;
|
||||
declare function withRouter<P>(component: ComponentConstructor<P & WithRouterProps>, options?: Options): ComponentClass<P>;
|
||||
|
||||
export default withRouter;
|
||||
|
||||
@@ -20,7 +20,8 @@ import {
|
||||
RouterContext,
|
||||
LinkProps,
|
||||
RedirectFunction,
|
||||
RouteComponentProps
|
||||
RouteComponentProps,
|
||||
WithRouterProps
|
||||
} from "react-router";
|
||||
import { createHistory, History } from "history";
|
||||
|
||||
@@ -71,11 +72,7 @@ class Master extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
interface DashboardProps {
|
||||
router: InjectedRouter;
|
||||
}
|
||||
|
||||
class Dashboard extends React.Component<DashboardProps> {
|
||||
class Dashboard extends React.Component<WithRouterProps> {
|
||||
static staticMethodToBeHoisted(): void { }
|
||||
|
||||
navigate() {
|
||||
|
||||
Reference in New Issue
Block a user