React - how to determine if component is stateless/functional?

Question

I have functional/stateless component and component which inherited from React.Component:

const Component1 = () => (<span>Hello</span>)

class Component2 extends React.Component {
  render() {
    return (<span>Hello</span>)
  }
}

How can I determine if component is stateless or not? Is there any official way?

isStateless(Component1) // true
isStateless(Component2) // false

Show source
| javascript   | reactjs   2017-01-05 16:01 1 Answers

Answers to React - how to determine if component is stateless/functional? ( 1 )

  1. 2017-01-05 16:01

    you can check it's prototype, for example:

    function isStateless(Component) {
        return !Component.prototype.render;
    }
    

Leave a reply to - React - how to determine if component is stateless/functional?

◀ Go back