The Pillars of React: Components, Props & State

Discover the three fundamental concepts that power every interactive React application, from simple buttons to complex dashboards.

Lesson ProgressStep 1 of 10

Hello, Alice

Count: 0

🎉
0 EXP

Welcome! Let's explore the three core pillars of React: Components, Props, and State.

// Starting our journey...

Components & JSX

**Components** are the heart of React. They are independent, reusable pieces of code that return a description of the UI. Think of them like LEGO bricks; you can build a simple `Button` or an entire complex `Page` by combining them.

In modern React, a component is just a JavaScript function that returns **JSX** (JavaScript XML). JSX looks like HTML but is actually JavaScript. It lets you write your UI structure in a declarative way.

function Welcome() {
  return <h1>Hello, world!</h1>;
}

You can use JavaScript expressions inside JSX by wrapping them in curly braces ``.

System Check

What is JSX?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🧱
Component Constructor

Build a valid React functional component with JSX.

🎁
Prop Passer

Correctly pass and use props in a component.

🔄
State Manager

Implement interactive state using the useState Hook.

Mission: Build an Interactive Counter

Complete the `Counter` component. It must:
1. Use the `initialCount` **prop** to set its initial state.
2. Use **state** to track the current count.
3. Increment the count by 1 when the button is clicked.

A.D.A. Feedback:

> System integrity looks stable. All checks passed!

Challenge: Order the Concepts

Drag the definitions into the correct order to match the concepts on the left.

Props
State
Component
Data passed from parent (read-only)
A component's private, internal memory
A reusable, independent piece of UI

Challenge: Complete the Component

Fill in the missing parts to create a component that uses both props and state.

function UserProfile({ &#123;) {const [, ] = (true);return <div>Hello, {prop}</div>}

Consult A.D.A.

Community Holo-Net

Peer Project Review

Submit your "Interactive Counter" project for feedback from other Net-Runners.

React's Pillars in Practice: A Deep Dive

Understanding Components, Props, and State abstractly is one thing. Seeing how they weave together to create a living, breathing application is another. These three concepts form a system of logic that dictates how a React application functions, handles data, and reacts to user interaction. Let's explore each one in exhaustive detail.

1. Components: The Reusable Blueprint

At the most basic level, a component is a JavaScript function that returns React elements (usually written in JSX) that describe a piece of the UI.

  • Functional Components: This is the modern standard. They are simple, clean, and use **Hooks** (like `useState`) to manage state and other React features.
  • Class Components: The older way of writing components. You'll still see them in older codebases. They use `this` and `this.setState()` and have lifecycle methods.

The true power of components is **composition**. You build small, dumb components (like a `Button` or `Avatar`) and assemble them inside larger, "smart" components (like a `UserProfileCard`) which are then assembled into a `Page`. This makes your code incredibly modular and easy to debug.

// Small, reusable "dumb" component
function Button({ label, onClick }) {
  return <button onClick={onClick}>{label}</button>;
}

// "Smart" component that uses the dumb one
function UserProfile() {
  const [name, setName] = useState('Alice');

  const handleUpdateName = () => {
    setName('Bob');
  };

  return (
    <div>
      <p>User: {name}</p>
      <Button label="Change Name to Bob" onClick={handleUpdateName} />
    </div>
  );
}

2. Props: The One-Way Data Channel

Props (short for "properties") are the *only* way data flows from a parent component to a child component. This is the core of React's **one-way data flow**.

  • Immutability: Props are **read-only**. A child component can *never* modify the props it receives. If it tries, React will throw an error. This ensures predictability; you always know where data came from.
  • Destructuring: It's standard practice to destructure props in the function signature for clarity: `function Button({ label, onClick })` is cleaner than `function Button(props)` and using `props.label`.
  • `props.children`: A special prop that contains whatever you pass *between* the opening and closing tags of your component.
// Using props.children
function Card({ title }) {
  return (
    <div className="card">
      <h2>{title}</h2>
      {props.children}
    </div>
  );
}

// Rending the Card
<Card title="My Info">
  <p>This paragraph is passed as props.children!</p>
</Card>

3. State: The Component's Private Memory

If props are data from the outside, state is a component's own, private, internal data. This is what makes a component interactive. When state changes, React **re-renders** the component and its children.

The `useState` Hook is the primary tool for this.

const [value, setValue] = useState(initialValue);
  • `value`: The current value of this piece of state.
  • `setValue`: The **setter function**. You *must* call this function to change the state.
  • Asynchronous Updates: State updates are not immediate. React batches them for performance. This means `console.log(value)` right after `setValue(newValue)` will show the *old* value.
  • Functional Updates: When your new state depends on the previous state (like a counter), always use the functional update form to avoid bugs:

❌ Bad Practice

// This can be buggy if updates are batched
setCount(count + 1);

✔️ Good Practice

// This is always safe
setCount(prevCount => prevCount + 1);

The Holy Grail: "Lifting State Up"

This is the pattern that ties everything together. What happens when two different child components need to share the same state?

You don't share state. Instead, you **"lift" the state up** to their closest common parent component.

  • The **Parent** component owns the `useState`.
  • It passes the **state value** down as a `prop` to both children (or any child that needs to read it).
  • It passes the **setter function** down as a `prop` to the child that needs to *change* the state (e.g., an input or button).

This way, the data still flows down (one-way data flow), but the function to *change* the data at the source is passed down, allowing the child to trigger an update in the parent.

Key Takeaway: **Components** are the UI blocks. **Props** are how you pass data into them. **State** is how they remember things that change. Master this trio, and you've mastered the core of React.

React Core Concepts Glossary

Component
A self-contained, reusable piece of the user interface. In modern React, this is typically a JavaScript function that returns JSX.
Props
Short for "properties". A read-only object of data passed from a parent component down to a child component to customize it.
State
Data that is managed *within* a component. It is private to that component and can change over time, causing the component to re-render.
Hook
Special functions (like `useState`) that let you "hook into" React features like state and lifecycle methods from within functional components.
`useState`
The primary Hook for adding state to a functional component. It returns an array containing the current state value and a setter function.
JSX
JavaScript XML. A syntax extension for JavaScript that looks like HTML. It allows you to write UI descriptions in a declarative, familiar way.
One-Way Data Flow
The core principle in React that data has one, and only one, way of being transferred: downwards from parent to child components via props.
Immutability
The concept that data (like props or state) should not be changed directly. Instead of modifying an object, you create a new one. This is crucial for React to detect changes.
Lifting State Up
A common pattern where you move state from a child component to its closest common parent, and then pass the state and setter function down via props.
Render
The process where React runs your component function and generates a description of the UI (what will be shown on the screen).
Re-render
When a component's state or props change, React "re-renders" it (runs the function again) to get the new UI description and update the screen.
`props.children`
A special prop that holds any content passed between the opening and closing tags of a component, allowing for flexible component composition.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching React and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest React v18 specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!