State vs Props

 State:-

State is used to store data and information about components .state is an updatebal structure and it can change over time.

Change in state happens when the user is in an action or system event. State determines the behaviour of a component, state is also defined how it behaviour.

State is used to represent local state and information of components. A state must be kept as simple as possible. It can be accessed by the component or modified by the component directly.


Props:-

Props is a read only component. It is an object which is used to store the value of attribute .Props work similar to an HTML attribute. 

Props are allowed to pass data from component to component. 

Props is similar to function arguments and can be passed to the component the same way as an argument passed in a function.

Props are immutable , so props can not modify inside the component.


Difference between state and props



Props

State

1

Props are read only

State can change

2

Data can not change

Data can be change

3

It allow to pass data from component to component

It holde the data and information about component.

4

Props can be access by child component

State can not be accessed by the child component.

5

Stateless components can have props.

Stateless components can not have a state.



example of state and props:- state , props

Post a Comment

0 Comments