Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to wrap stateless component with react-click-outside? #33

Closed
gitowiec opened this issue Mar 5, 2018 · 2 comments
Closed

How to wrap stateless component with react-click-outside? #33

gitowiec opened this issue Mar 5, 2018 · 2 comments

Comments

@gitowiec
Copy link

gitowiec commented Mar 5, 2018

As said in topic, could You please provide example?
I use recompose and withHandlers.
All I got is error Warning: Stateless function components cannot be given refs. Attempts to access this ref will fail.

@kentor
Copy link
Owner

kentor commented Mar 6, 2018

You can't as it stands. Why do you need it to be a stateless component?

@kentor kentor closed this as completed Apr 13, 2018
@ADagen
Copy link

ADagen commented Jul 19, 2018

Sorry guys for interrupting you, but you can.

@gitowiec as you already use recompose, just unleash the power of Pandora's box lifecycle:

const yourEnhancer = compose(
    withHandlers({
        someHandler: () => () => console.log('Hurray, it works!'),
    }),
    ...

    withClickOutside,
    lifecycle({
        handleClickOutside() {
            this.props.someHandler();
        },
    }),

    ...
),

@kentor how do you feel about add this to the README.md? Sure this trick is't limited to recompose, one can use any suitable HOCs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants