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

Wrapping stateless functional components #4

Open
montemishkin opened this issue Oct 11, 2015 · 3 comments
Open

Wrapping stateless functional components #4

montemishkin opened this issue Oct 11, 2015 · 3 comments

Comments

@montemishkin
Copy link
Collaborator

We should support wrapping stateless functional components (see here).

This shouldn't be too hard. Our decorator should check if the thing its wrapping has extended React.Component. If it has, do as we already do. If it hasn't (and is a function) then we make a class that extends React.Component that will essentially look something like

class WrappedComponent extends React.Component {
    render() {
        return wrapped_stateless_functional_component(this.props)
    }
}

and then use this WrappedComponent like we already do.

@montemishkin montemishkin changed the title Wrapping Stateless functional components Wrapping stateless functional components Oct 11, 2015
@montemishkin
Copy link
Collaborator Author

I'd imagine that (unless I'm missing something here) lots of people are going to be implementing this same functionality, which detects if a component extends React.Component or is a stateless functional component, and then converts to a class extending React.Component if it is stateless. So maybe that part of the solution should be separated into a standalone npm package.

@montemishkin
Copy link
Collaborator Author

Looks like react already has this feature for detecting if a component is stateless functional or not:

if (Component.isReactClass) {
    // then it is a class which extends React.Component
}

See here (and the commit which closed that issue) for more info.

@montemishkin
Copy link
Collaborator Author

Also, found this for turning stateless functional components into react classes.

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

1 participant