Add innerRef prop to <Link> component

An `innerRef` prop was added to <Link> in `react-router-dom@4.2`

The node will be an anchor tag, which is why I made the callback accept
an `HTMLAnchorElement` rather than an `HTMLElement`, however this isn't
explicitly documented.
This commit is contained in:
Philip Jackson
2018-03-26 14:37:03 +13:00
parent 106d393592
commit fd991797cd
2 changed files with 9 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/ReactTraining/react-router
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
// Huy Nguyen <https://github.com/huy-nguyen>
// Philip Jackson <https://github.com/p-jackson>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
@@ -44,6 +45,7 @@ export class HashRouter extends React.Component<HashRouterProps, any> {}
export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
to: H.LocationDescriptor;
replace?: boolean;
innerRef?: (node: HTMLAnchorElement | null) => void;
}
export class Link extends React.Component<LinkProps, any> {}

View File

@@ -2,7 +2,8 @@ import * as React from 'react';
import {
NavLink,
NavLinkProps,
match
match,
Link
} from 'react-router-dom';
import * as H from 'history';
@@ -19,3 +20,8 @@ export default function(props: Props) {
<NavLink {...rest} isActive={isActive}/>
);
}
<Link to="/url" />;
const acceptRef = (node: HTMLAnchorElement | null) => {};
<Link to="/url" replace={true} innerRef={acceptRef} />;