mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-01 19:45:48 +08:00
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.
28 lines
627 B
TypeScript
28 lines
627 B
TypeScript
import * as React from 'react';
|
|
import {
|
|
NavLink,
|
|
NavLinkProps,
|
|
match,
|
|
Link
|
|
} from 'react-router-dom';
|
|
import * as H from 'history';
|
|
|
|
const getIsActive = (extraProp: string) => (match: match<any>, location: H.Location) => !!extraProp;
|
|
|
|
interface Props extends NavLinkProps {
|
|
extraProp: string;
|
|
}
|
|
|
|
export default function(props: Props) {
|
|
const {extraProp, ...rest} = props;
|
|
const isActive = getIsActive(extraProp);
|
|
return (
|
|
<NavLink {...rest} isActive={isActive}/>
|
|
);
|
|
}
|
|
|
|
<Link to="/url" />;
|
|
|
|
const acceptRef = (node: HTMLAnchorElement | null) => {};
|
|
<Link to="/url" replace={true} innerRef={acceptRef} />;
|