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

Question

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

Answers 1
Added at 2017-01-05 16:01
Tags
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
Answers to

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

nr: #1 dodano: 2017-01-05 16:01

you can check it's prototype, for example:

function isStateless(Component) {
    return !Component.prototype.render;
}
Source Show
◀ Wstecz