Wednesday, September 9, 2020

Props vs State

 We have hear many time about props and state. Let's see much more about them.

        



                                                                    Props vs State

  • Props get passed to the component whereas state managed within the component.
  • Props can be passed as function parameter.State is a variable declared in the class component.
  • There is no state in functional component. Functional component have props.You can use state in function component through hooks.
  • Props are immutable[handle by parent cannot changed by children]. Whereas state can be changes[it managed inside the component so, component have right to change them].
  • In class state can be accessible as {this.state.key}. Whereas in function component need to use useState hook to use state.
  • In functional component props can be access as {props.key}. Whereas, in class component props is access as {this.props.key}.
  • You can use setState method to modify state in class. And  useState hook in functional component to modify and set state.

No comments:

Post a Comment