question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for stateless components

See original GitHub issue

I tried to use this lib with recompose:

const controller = compose(
    withHandlers({
        handleClickOutside: (props) => (event) => null // do something
    }),
    onClickOutside
);

const component = controller((props) => <div>...</div>);

Unfortunately, onClickOutside HOC expects component with handleClickOutside method defined in component itself, so it doesn’t work with stateless components.

Right now I’m using simple component using existing API which I use a root component in my stateless one:

@onClickOutside
class OutsideClickHandler extends Component {
  handleClickOutside() {
    this.props.handleClickOutside();
  }

  render() {
    return this.props.children;
  }
}

Question is: Is it worth to include such a component in this library? Is there a better way how to support stateless components or take handler function from props?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
davishmcclurgcommented, Sep 6, 2016
0reactions
Pomaxcommented, Sep 6, 2016

Hm, this sounds like it needs a new issue filed, specifically to check whether the HOC is wrapping a true component, or just a stateless render function. Want to file one?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stateful and Stateless Components in React
Today, we're going to review what stateful and stateless components are in React, how you can tell the difference, and the complex process ......
Read more >
Stateless Components From Stateful Components Cheatsheet
In React, a stateful component is a component that holds some state. Stateless components, by contrast, have no state. Note that both types...
Read more >
What are the advantages of stateless components? - O'Reilly
The answer is performance. Stateless functional components can be rendered faster. One of the reasons why this is the case is because stateless...
Read more >
React Stateless Functional Components: Nine Wins You Might ...
Stateless functional components don't support state or lifecycle methods. This is a good thing. Why?
Read more >
Support functional stateless components · Issue #45 - GitHub
I am currently working on #261, and I have encountered a similar issue. Calling .text() directly on the wrapper does not work for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found