ReactJS difference between stateful and stateless

前端 未结 3 868
执念已碎
执念已碎 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:55

    Functional Component or Stateless component

    1. Functional component is like pure function in JavaScript.
    2. Functional component is also called as a stateless component.
    3. The functional component only receives props from parent component and return you JSX elements.
    4. The functional component doesn’t play with any lifecycle methods of React and doesn’t play with the component state.

    Class component or statefull component

    1. React class component is called as a stateful component.
    2. Stateful component plays with all life cycle methods of React.
    3. This component will modify state.

    That’s the major differences

    If you have knowledge about pure function in JavaScript then you can understand functional or stateless component easily.

提交回复
热议问题