Hello! Welcome to the third module of our course. We're now moving into one of the most fundamental and powerful concepts in React: managing interactivity.
Introduction
In the previous module, we focused on the static structure of a React application. You learned how to break down a UI into a component tree, pass data down from parents to children using props, and send information back up using callback functions. This established the "one-way data flow" principle.
However, a key piece of the puzzle is still missing. Props are read-only from the child component's perspective. So, how does a component remember information that changes over time, like the text in an input field, whether a button has been clicked, or data fetched from an API?
This is where state comes in. In this lesson, we will explore the conceptual foundation of state. Your learning outcome is to explain what state is in a React component and how it differs from props. We will define what constitutes state, why it's essential for creating dynamic user interfaces, and establish a clear mental model for distinguishing it from the props you're already familiar with. In our last lesson's final exercise, you saw a sneak peek of this when the App component managed the visibility of an alert; that visibility flag was its state. Today, we'll formalize that concept.
Revisiting Props: A Component's Configuration
Let's quickly recap what we know about props. Props (short for "properties") are the mechanism for passing data from a parent component to a child component.
Given your computer science background, the most accurate analogy is that props are to a component what arguments are to a function. They allow you to configure a component's appearance and behavior from the outside.
// A simple JavaScript function
function greet(name) {
return `Hello, ${name}!`;
}
greet('Alice'); // 'Alice' is the argument
// A React component
function Greeting({ name }) {
return <p>Hello, {name}!</p>;
}
<Greeting name="Alice" /> // 'name' is the prop
The key characteristic of props is that they are read-only within the component that receives them. A component cannot—and should not—change its own props. This immutability is what ensures the predictable, top-down data flow in React.
Introducing State: A Component's Memory
If props are the arguments passed into a component, then state is like a component's private, internal memory. It is data that is managed inside a component and can change over time in response to user actions or other events.
The most critical feature of state is that when a component's state changes, React automatically re-renders the component and its children to reflect the new state in the UI.
This is fundamentally different from a regular variable inside a component function. A normal variable is re-created from scratch on every render, forgetting its previous value. State, on the other hand, is preserved by React between renders.
Let's start building a strong mental model for this distinction.
A visual guide to React Mental models
The article 'A visual guide to React Mental models' by Obed Parla offers an excellent analogy using boxes. It will help you visualize the relationship between a component, its props, and its state.
Please read two sections: Start at 'component’s props are the same as a function’s arguments' and read to the end of that section. This reinforces the function argument analogy for props. Then, read the section 'Fitting React’s State Into Our Mental Model'. Focus on the 'box' analogy: props are ingredients coming into the box from the outside, while state is a special property inside the box that persists across re-renders.
Props vs. State: A Detailed Comparison
Now that we have initial definitions for both, let's crystallize the differences. The following two videos provide concise explanations from slightly different angles.
First, let's watch this video from Web Dev Simplified. It clearly lays out the core distinction: where the data is managed.
Watch the video from 00:40 to 03:43 and the summary from 04:36 to 05:30. Pay close attention to the key idea: props are handled outside the component and passed in, while state is handled inside the component and can be updated there.
ReactJS Tutorial 22 : State In React, Props V/S State In React
This next video from Code Stoic emphasizes the immutability of props as the primary reason for state's existence.
Watch the first three and a half minutes of this video (00:00 - 03:30). The analogy of state being like a 'variable declared inside a function body' is a useful extension of the props-as-arguments model.
Let's summarize these points in a table and with a diagram.
| Feature | Props | State |
|---|---|---|
| Origin | Passed to a component from its parent (External). | Managed within the component itself (Internal). |
| Mutability | Immutable. The component cannot change its own props. | Mutable. The component can update its own state. |
| Purpose | To configure a component and pass data down the component tree. | To manage data that changes over time and drives interactivity. |
| Lifecycle | A component receives new props if its parent re-renders with new data. | State is initialized on the first render and persists across re-renders. |
| Analogy | Arguments to a function. | Local variables in a function's scope that persist. |
This diagram provides a clear visual summary of the data flow.

Deciding What Should Be State
A common challenge for beginners is figuring out what data should be state, what should be props, and what should be neither. The official React documentation provides an excellent heuristic.
For any piece of data in your application, ask yourself three questions:
- Is it passed in from a parent via props? If so, it isn’t state.
- Does it remain unchanged over time? If so, it isn’t state (it could be a hardcoded constant).
- Can you compute it based on existing state or props? If so, it definitely isn’t state.
If the answer to all three is "no," then you have likely found a piece of state. The goal is to find the minimal but complete representation of state your UI needs.
Let's read the section from the official 'Thinking in React' guide that formalizes this process. It's a critical skill for designing stateful components.
Please read the sections 'Step 3: Find the minimal but complete representation of UI state' and the 'Props vs State' deep dive within it. The walkthrough of identifying state for a searchable product list is a perfect practical example of applying the three-question heuristic.
Test your understanding!
Imagine you're building a UserProfileCard component. You need to display the following pieces of information:
- The user's full name.
- The URL for the user's avatar image.
- The number of followers the user has.
- A 'like' button that shows a count. The count should increase every time the button is clicked.
- An "online status" indicator that is green if the user is online and gray otherwise. The card should periodically check the server for the user's latest status.
For each of these 5 data points, decide whether it should be managed as props, state, or if it's a derived value that doesn't need to be stored at all. Justify your answers using the three-question heuristic.
Show answer
Here's a breakdown:
- User's full name: Props. This is core identifying information about the user profile being displayed. It's passed in from a parent and is unlikely to change within the context of this card.
- Avatar URL: Props. Same as the name. It's configuration data passed down from a parent.
- Number of followers: Props. This data comes from an external source (your database/API) and would be passed into the card from a parent component that fetches user data. While the number can change over time, the
UserProfileCarditself isn't responsible for this change; it just displays the number it's given. - 'Like' count: State. This is a classic example of state.
- It's not passed from a parent. The interaction happens inside this component.
- It changes over time (every time the user clicks).
- It cannot be computed from other props or state. It's a unique piece of memory for this component.
- Online status: State.
- It's not passed from a parent in its final form. The component itself is responsible for fetching it.
- It changes over time as the component gets new information from the server.
- It can't be computed from other data available to the card. It's a piece of information the component needs to remember and update internally.
Conclusion
In this lesson, we established the crucial difference between props and state, the two types of "model" data in React.
Key Takeaways:
- Props are like function arguments. They are passed from parent to child, are read-only, and are used to configure a component from the outside.
- State is like a component's private memory. It is managed internally, is mutable, and is used to handle data that changes over time.
- A change in either props or state will cause a component to re-render, ensuring the UI stays in sync with the data.
- To decide if a piece of data should be state, ask if it's passed via props, if it's static, or if it can be computed from other data. If the answer to all is no, it's likely state.
Next Steps
You now have the conceptual framework for understanding why and when to use state. In our next lesson, we will get practical. You will learn how to use the first and most common React Hook, useState, to add local state to your functional components and bring them to life with interactivity.