update code (#14700)

close  #12749
This commit is contained in:
zombieJ 2019-02-02 18:30:40 +08:00 committed by GitHub
parent ff41bfe2fb
commit 4668bf6ddd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import * as React from 'react'; import * as React from 'react';
import * as PropTypes from 'prop-types'; import * as PropTypes from 'prop-types';
import { polyfill } from 'react-lifecycles-compat';
import classNames from 'classnames'; import classNames from 'classnames';
import { AntAnchor } from './Anchor'; import { AntAnchor } from './Anchor';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
@ -12,7 +13,7 @@ export interface AnchorLinkProps {
className?: string; className?: string;
} }
export default class AnchorLink extends React.Component<AnchorLinkProps, any> { class AnchorLink extends React.Component<AnchorLinkProps, any> {
static defaultProps = { static defaultProps = {
href: '#', href: '#',
}; };
@ -29,10 +30,10 @@ export default class AnchorLink extends React.Component<AnchorLinkProps, any> {
this.context.antAnchor.registerLink(this.props.href); this.context.antAnchor.registerLink(this.props.href);
} }
componentWillReceiveProps(nextProps: AnchorLinkProps) { componentDidUpdate({ href: prevHref }: AnchorLinkProps) {
const { href } = nextProps; const { href } = this.props;
if (this.props.href !== href) { if (prevHref !== href) {
this.context.antAnchor.unregisterLink(this.props.href); this.context.antAnchor.unregisterLink(prevHref);
this.context.antAnchor.registerLink(href); this.context.antAnchor.registerLink(href);
} }
} }
@ -79,3 +80,7 @@ export default class AnchorLink extends React.Component<AnchorLinkProps, any> {
return <ConfigConsumer>{this.renderAnchorLink}</ConfigConsumer>; return <ConfigConsumer>{this.renderAnchorLink}</ConfigConsumer>;
} }
} }
polyfill(AnchorLink);
export default AnchorLink;