Props are read-only inputs passed from a parent component to a child; state is data that a component owns and can change, and changing state makes React re-render the component.
Props (properties)
- Passed like HTML attributes:
<Greeting name="Riya" />. - Immutable inside the child (the child must not modify them).
- Allow one component to be reused with different data.
function Greeting(props) {
return <h2>Hello, {props.name}!</h2>;
}
function App() {
return (
<div>
<Greeting name="Riya" />
<Greeting name="Aman" />
</div>
);
}
State
- Private data managed inside the component (with
useStatein function components, orthis.state/this.setStatein class components). - Updated only through the setter function, never by direct assignment.
- Each update triggers a re-render with the new value.
import { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>+1</button>
</div>
);
}
Using both together: a parent can keep state and pass it down as props, e.g. <Display value={count} />. Data flows one way, from parent to child.
| Props | State |
|---|---|
| Passed from parent | Created inside the component |
| Read-only | Changeable via setter |
| Used to configure a component | Used for data that changes over time (input text, counters, fetched data) |