Fix attempting to observe non-DOM refs in Link (#7249)

handleRef isn't called with valid DOM node
This commit is contained in:
JJ Kasper 2019-05-06 08:44:18 -05:00 committed by Tim Neutkens
parent 3a5c1ebe04
commit b97a47d273

View file

@ -113,8 +113,8 @@ class Link extends Component<LinkProps> {
this.cleanUpListeners()
}
handleRef(ref: any) {
if (IntersectionObserver && ref) {
handleRef(ref: Element) {
if (IntersectionObserver && ref && ref.tagName) {
this.cleanUpListeners = listenToIntersections(ref, () => {
this.prefetch()
})
@ -193,11 +193,15 @@ class Link extends Component<LinkProps> {
// This will return the first child, if multiple are provided it will throw an error
const child: any = Children.only(children)
const props: {
onMouseEnter: React.MouseEventHandler,
onClick: React.MouseEventHandler,
href?: string,
ref?: any,
} = {
ref: (el: any) => this.handleRef(el),
onMouseEnter: () => {
this.prefetch()
},
onClick: (e: React.MouseEvent) => {
if (child.props && typeof child.props.onClick === 'function') {
child.props.onClick(e)