Files
DefinitelyTyped/types/react-router-dom/react-router-dom-tests.tsx
Philip Jackson fd991797cd 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.
2018-03-26 14:37:03 +13:00

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} />;