import * as React from 'react'; import { Component, MouseEvent, StatelessComponent } from 'react'; import { render } from 'react-dom'; import onClickOutside from 'react-onclickoutside'; interface TestStatelessProps { disableOnClickOutside(): void; enableOnClickOutside(): void; nonClickOutsideProp: string; } function TestStateless(props: TestStatelessProps) { return (
{props.nonClickOutsideProp}
); } const TestConfigObject = onClickOutside(TestStateless, { handleClickOutside: () => console.log('Stateless HandleClickOutside'), excludeScrollbar: true }); render( , document.getElementById("main") ); const TestStatelessWrapped = onClickOutside(TestStateless); render( console.log('Stateless HandleClickOutside')} excludeScrollbar />, document.getElementById("main") ); class TestComponent extends React.Component<{ disableOnClickOutside(): void; enableOnClickOutside(): void; }> { handleClickOutside = () => { console.log('this.handleClickOutside'); } logProps = () => { console.log(this.props); } render() { this.props.disableOnClickOutside(); this.props.enableOnClickOutside(); return (
TestComponent
); } } const WrappedComponent = onClickOutside(TestComponent); const wrappedComponentRef: React.RefObject> = React.createRef(); render( , document.getElementById("main") ); if (wrappedComponentRef.current) { wrappedComponentRef.current.getInstance().logProps(); }