Skip to main content

Command Palette

Search for a command to run...

🟦 State vs. Props in React .

🟦 State vs. Props in React β€” A Complete Guide for Beginners | Hasenode

Published
β€’3 min readβ€’View as Markdown
🟦 State vs. Props in React .

When building modern React applications, two core concepts you will use every day are State and Props. These two terms may sound similar, but they serve very different purposes. Understanding the difference between them is essential for writing clean, reusable, and dynamic React components.

In this Hasenode blog, we’ll break down what State is, what Props are, and how they differ, with simple examples to make everything clear.

πŸ”Ή What Are Props?

Props (short for properties) are used to pass data from one component to another β€” typically from a parent component to a child component.

Key Features of Props

  • Read-only (cannot be modified by the child component)

  • Used for data flow from parent to child

  • Make components reusable

  • Behave like function parameters

βœ” Example of Props

function Welcome(props) {
  return <h2>Hello, {props.name}!</h2>;
}

function App() {
  return <Welcome name="Sagar" />;
}

Here:

  • App β†’ Parent component

  • Welcome β†’ Child component

  • name="Sagar" is passed as a prop


πŸ”Ή What Is State?

State is used to manage data that changes over time within a component. It is mutable, meaning a component can update its own state.

Key Features of State

  • Mutable (can change over time)

  • Used to handle dynamic data

  • Updates cause the component to re-render

  • Managed inside the component itself

βœ” Example of State

import { useState } from "react";

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increase</button>
    </div>
  );
}

Here:

  • count is part of the component’s state

  • setCount() updates the state

  • UI updates automatically when the state changes


πŸ†š State vs. Props β€” Quick Comparison Table

FeatureStateProps
DefinitionInternal data of a componentData passed from parent to child
MutabilityMutable (can change)Immutable (read-only)
Owned byThe component itselfParent component
Used forDynamic data, UI updatesPassing data, configuration
Who can update it?The componentParent component only
Triggers re-render?YesYes (when parent re-renders)

🎯 When to Use What?

βœ” Use State when:

  • You need to store dynamic or interactive data

  • A component needs to update its UI

Examples: Counter, form inputs, toggles, modals, cart items


βœ” Use Props when:

  • You want to pass data into a child component

  • You need to make components reusable

Examples: Passing name, image, colors, lists, action handlers


🧠 Simple Rule to Remember

Props are for passing data.
State is for managing data.

Props = external
State = internal


πŸš€ Final Thoughts

Mastering State and Props is the foundation of becoming great at React.
Props help you share data across components.
State helps you change the UI dynamically.

When you understand how they work together, building interactive interfaces becomes effortless.