Trying to differentiate state and prop would be one of the most conceptually confusing for beginners in React, so I break it down into points.
Props(properties)
Components receive data from outside the component with props.
Are what we use to pass data between our components in React which it only goes from parent to child component. So components receive data from parent component with props.
Props can be anything. they can be strings, arrays, objects, functions, etc. Callback function can also be passed as prop to initiate it’s state changes(updating state) from the child component.
One limit to props is that it is immutable, meaning you shouldn’t ever directly change the value of props.
State
Components can create and manage their own local state
State is mutable
When state changes, it trigger updates in components
Great thing about state is that it’ll only update part of the app component that is influence by the data changes instead of updating the whole app.
State should not be modified directly, but it can be modified with a special method called
setState
(Class Component) OR using React hook (Functional Component)
Blog post moved from my Learn blog
Top comments (1)
❤❤