What is the difference between props and state in React?
Quick answer
Props are read-only inputs passed from a parent component, while state is data a component owns and can change over time, which triggers a re-render when updated.
Props make a component reusable: the parent decides the values, and the child must not modify them. State is private memory for a component, created with useState or useReducer. Updating state tells React to re-render that component with the new value.
A good rule is to keep state as low as possible in the tree, and lift it up to the closest common parent only when two components need to share it. Data that can be calculated from props or state should be computed during render and not stored in extra state.
function Counter({ step }) { // step is a prop (read-only)
const [count, setCount] = useState(0); // count is state (owned here)
return <button onClick={() => setCount(count + step)}>{count}</button>;
}
<Counter step={5} />Key points
- Props flow down, are read-only and come from the parent
- State is owned by the component and changes cause re-renders
- Derived values should be calculated, not stored in state