The state is an update-able structure that is used to contain data or information about the component and can change over time. The change in 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 component and how it will render. A state must be kept as simple as possible. It represents the component's local state or information. it can only be accessed or modified inside the component or by the component directly.
Props are read-only component. It is an object which stores the value of attributes of a tag and work similar to the HTML attributes. It allows passing data from one component to other components. It is similar to function arguments and can be passed to the component the same way as arguments passed in a function. Props are immutable so we cannot modify the props from inside the component.
State: State changes can be asynchronous.
Props: Props are read-only.
State: State is mutable.
Props: Props are immutable.
State: State holds information about the components.
Props: Props allow you to pass data from one components to other components as an argument.
State: State can be used for rendering dynamic changes with the component.
Props: Props used to communicate between components.
State: State cannot be accessed by child components.
Props: Props can be accessed by child components.
State: The state is internal and controlled by the React Component itself.
Props: Props are external and controlled by what ever renders the component.
State: State cannot make components reusable.
Props: Props make components reusable.
Below table will guide you about the changing in props and state.
|Can get initial value from parent component?
|Can be changed by parent Component?
|Can set default values inside component?
|Can change inside component?
|Can set initial value for child component?
|Can change in child component?
And last but not least, The component state and props share some common similarities.
|State and Props
|Both can contain default values.
|Both are read-only when they are using this.