/    /  ReactJS- State Vs. Props

State Vs. Props

 

State

The React state is an updatable structure that is used to contain data or information about the component and can change over time. The change in react state can happen as a response to user action or system event. It is the heart of the react component which determines the behavior of the react component and how it will render. A react state must be kept as simple as possible. It represents the react component’s local state or information. It can only be accessed or modified inside the react component or by the react component directly.

 

Props

React Props are read-only components. It is an object which stores the value(data) of attributes of a tag and works similarly to the HTML attributes. It allows passing data(information) from one component to other components. It is similar to function arguments and can be passed to the react component the same way as arguments passed in a function. React Props are immutable so we cannot modify the React props from inside the component.

 

Difference between State and Props:

SNPropsState
1Props are read-onlyReact State changes can be asynchronous.
2Props are immutable.State is mutable.
3pass data(information) from one component to other components as an argument.React State holds information about the components.
4React Props can be accessed by the child component.React State cannot be accessed by child components.
5React Props are used to communicate between components.used for rendering dynamic changes with the React component.
6Stateless raect component can have Props.Stateless react components cannot have State.
7React Props make components reusable.React State cannot make components reusable.
8external and controlled by whatever renders the react component.internal and controlled by the React react Component itself.