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

Using react-reactonlickoutside with React.forwardRef results in a runtime error

Open gaborsar opened this issue 6 years ago • 8 comments

Using the following component that uses React.forwardRef:

const TestComponent = onClickOutside(
    React.forwardRef((props, ref) => <div {...props} ref={ref} />)
);

Leads to the following error:

Uncaught TypeError: Cannot read property 'isReactComponent' of undefined
    at onClickOutside.render (react-onclickoutside.es.js:329)
    at finishClassComponent (react-dom.development.js:13727)
    at updateClassComponent (react-dom.development.js:13690)
    at beginWork (react-dom.development.js:14489)
    at performUnitOfWork (react-dom.development.js:17014)
    at workLoop (react-dom.development.js:17054)
    at HTMLUnknownElement.callCallback (react-dom.development.js:149)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:199)
    at invokeGuardedCallback (react-dom.development.js:256)
    at replayUnitOfWork (react-dom.development.js:16366)

As styled-components uses React.forwardRef, react-onclickoutside cannot be directly used with styled components. Related to: https://github.com/Pomax/react-onclickoutside/pull/293

gaborsar avatar Nov 15 '18 14:11 gaborsar

I am very glad they finally added this as a thing, because it solves a problem that is inherent to HOC implementations. That said, this is absolutely worth updating the code for, and then releasing it as a new major version that does away with the whole instance forwarding code this HOC has had to use for years now.

As per https://reactjs.org/docs/forwarding-refs.html#note-for-component-library-maintainers - let's use this! And mark it as breaking change.

/cc @Andarist

Pomax avatar Nov 24 '18 01:11 Pomax

Sure - doing a major release for this is cool 👍

Andarist avatar Nov 24 '18 09:11 Andarist

Any update on that?

ozluy avatar Apr 24 '19 09:04 ozluy

Any updates on this fix?

arthur-cen avatar May 07 '19 22:05 arthur-cen

@Andarist could you please update your PR

kevalbhatt avatar May 08 '19 05:05 kevalbhatt

is there any workaround now to use with styled-components?

adarrra avatar Jun 18 '19 14:06 adarrra

#326 should be able to work with forwardRef without a breaking change

NilSet avatar Jun 30 '19 03:06 NilSet

I've not had any free time to look at this before today, but I've left some questions on that PR - there's some odd things going on in it and I'd like to make sure those are all intentional.

Pomax avatar Aug 11 '19 17:08 Pomax