Open montemishkin opened 9 years ago
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.
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.
Also, found this for turning stateless functional components into react classes.
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 extendsReact.Component
that will essentially look something likeand then use this
WrappedComponent
like we already do.