Category: react
state and props
Published on 26 May 2026
Explanation
State in React is used to
store and manage dynamic data inside
a component.
Code:
const [count, setCount] = useState(0);
Explanation
Props are used to pass data
from a parent component to a
child component.
Code:
<User name="Praveen" />
Explanation
State can be updated using the
setter function returned by useState().
Code:
setCount(count + 1);
Explanation
Props are read-only and cannot be
modified inside the child component.
Code:
function User(props) {
return <h1>{props.name}</h1>;
}
Explanation
State manages internal component data, while
props help components communicate with each
other.
Code:
Parent Component --> Props --> Child Component