C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
State Vs. PropsStateThe state is an updatable 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. PropsProps are read-only components. 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. Difference between State and Props
The below table will guide you about the changing in props and state.
| |||||||||||||||||||||||||||||||||||
2. | Can be changed by parent Component? | Yes | No | ||||||||||||||||||||||||||||||||
3. | Can set default values inside Component? | Yes | Yes | ||||||||||||||||||||||||||||||||
4. | Can change inside Component? | No | Yes | ||||||||||||||||||||||||||||||||
5. | Can set initial value for child Components? | Yes | Yes | ||||||||||||||||||||||||||||||||
6. | Can change in child Components? | Yes | No |