state vs props in ReactJS

  • state is used to store the data that is needed by the component.
    While props is used to pass the data to child component from parent component.

  • state is mutable. This means, state can be changed.
    props is immutable. This means, child component can not change props. Because props are passed to child component from parent component and it is logical to change the data by the component who passed it, not the one which is receiving it.

  • state can only be in stateful components ( Class components ).
    props don't have this limitation.

Conclusion

In this section, we have learned about difference between state and props of component in ReactJS.
In the next section, you will learn about difference between stateful component and stateless component in ReactJS.