Statefull component in React


Every class component in Reactjs can be a Statefull component. A class component become Statefull under following condition

  1. It has a constructor with this.state ={ } statement
  2. A class uses the this.setState() method

With a Statefull component we can able to update UI based on various user interaction. The component will re-render the UI for us.

The state objects can be accessible through this.state.<variable> only and can be updated by calling the setState method.

The component can also updated from another component using props functions. Learn how this possible with props function. Here is the guide for you.

Remember a regular functional component is not a Statefull component. But it can be possible make them Statefull using Hooks, which is a React future.

Published by

Manoj

A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.