preactjs / preact-compat

ATTENTION: The React compatibility layer for Preact has moved to the main preact repo.
http://npm.im/preact-compat
MIT License
949 stars 148 forks source link

findDOMNode should return null if component.base is not set #430

Closed tomascasas closed 6 years ago

tomascasas commented 6 years ago

I am using this package to handle click outside events: https://www.npmjs.com/package/react-click-outside

It is throwing undefined error while calling domNode.contains() which is not defined. Checked to find that donNode is set to component.findDOMNode() which returns a DOM Node if set (ie: component.base) or the component which is not of DOM Node type and thus has no contains member.

Based on this: https://facebook.github.io/react/docs/react-dom.html#finddomnode

I think that this function: https://github.com/developit/preact-compat/blob/5ca57489b75c539a0ad022f3624d97d755c939b5/src/index.js#L397-L399 ... should be something like:

function findDOMNode(component) {
    return component && component.base || null;
}