Asked 6 years ago
31 Mar 2018
Views 1662
pratik

pratik posted

what is Stateless components and Stateful components in React js ?

what is Stateless components and Stateful components in React js ?
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

in React , class-based component has an additional property state , which hold a component’s private data , these are also known as Stateful components.

class Type extends React.Component {
  constructor() {
    super(); 
    this.state = {type: 'timer'}
  }
  
  render() {
    return (
      <div>
        {this.state.type}
      </div>
    );
  }
}


and Functional components are known as Stateless components

function Type(props) {
  return <div>{props.type}</div>
}

because it does not have property state.
Post Answer