Kevin Hooke Kevin Hooke -4 years ago 160
Javascript Question

React: what determines that a Stateless React component is actually a React component?

In ES6 syntax, it's easy to follow that a component that extends Component from React is a React component. For example:

import { Component } from 'react';
class ExampleComponent extends Component {
//render component content here

but if you rewrite this using the Stateless Component approach:

const ExampleComponent = (props) => {
//render component content here

... what happens behind the scenes so that this component inherits the lifecycle behavior from Component?

Answer Source

A stateless component as a function, acts as the body of the render method found in the lifecycle methods. When you define a component as a function, it is wrapped in a class's render method.

Component Class's render() === Stateless Component Function

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download