react-onclickoutside icon indicating copy to clipboard operation
react-onclickoutside copied to clipboard

Preact compatibility

Open tiansivive opened this issue 7 years ago • 4 comments

Does anyone know if there is any reason why this wouldn't work with preact?

From what I've been able to gather it should work just fine, however, when I try to use it it always throws out a : WrappedComponent lacks a function for processing outside click events specified by the handleClickOutside config option. error

tiansivive avatar Jan 10 '18 12:01 tiansivive

Could u paste in the code of how do you try to use this module?

Andarist avatar Jan 10 '18 17:01 Andarist

Hey, also had this same issue. I'm pretty sure it's an issue with this module checking if WrappedComponent.prototype.isReactComponent exists, which doesn't exist on preact components

So ended up with a small hack to fix it for myself, by adding a dummy isReactComponent method to the class:

class ColorPicker extends Component {
	...

  	isReactComponent() {}

	...
}

export default onClickOutside(ColorPicker);

Can also work on a pr for this, if that's ok

teevik avatar Apr 01 '18 18:04 teevik

@teevik thanks fam

imkimchi avatar Apr 14 '19 10:04 imkimchi

I'll be honest, this feels like something to offer as "extension" on Preact, not something to address in libraries designed for React? That snippet looks like an excellent thing to "publish". I love preact, but it cuts corners where it can in order to stay tiny, and that is guaranteed to break some libraries through no fault of those libraries.

You could write a class Component extends React.Component with a pass-through constructor, add in that single function, and then export that class with the same Component name but in your own namespace. Now people can import { Component } from 'patched-preact' or something and not have to add the function in every class they write themselves.

Pomax avatar Apr 14 '19 15:04 Pomax