ReactJS difference between stateful and stateless

前端 未结 3 872
执念已碎
执念已碎 2020-12-01 02:17

I am trying to understand the exact difference between React\'s stateful and stateless components. Ok, stateless components just do something, but remember nothing, while st

3条回答
  •  鱼传尺愫
    2020-12-01 02:59

    In a simple definition it can be explained as

    If the behaviour of a component is dependent on the state of the component then it can be termed as stateful component and if behaviour is independent of its state then it can be a stateless component.

    When something is “stateful”, it is a central point that stores information in memory about the app/component’s state. When something is “stateless”, it calculates its internal state but it never directly mutates it.

    The stateless components are sometimes referred as dumb components

    The main advantage stateless over stateful component is scalability and reusability.

    Now you can check the example components in @Davin Tryon Answer

提交回复
热议问题