Skip to main content

๐Ÿ“˜ React Mastery Series โ€” Day 19

Updated 3 min readMarkdown

Lifting State Up โ€” Master Component Communication in React

As your app grows, components need to talk to each other.

But hereโ€™s the rule in React:

๐Ÿ‘‰ Data flows one way (Parent โž Child)

So what if two sibling components need the same data?

Thatโ€™s where Lifting State Up comes in.


๐Ÿค” What is Lifting State Up?

Lifting State Up means moving state to the closest common parent so multiple components can share it.

Instead of each component managing its own state,
we move the state to their parent.


๐Ÿง  Why Do We Need It?

Imagine:

  • Component A updates data

  • Component B displays that data

If both are siblings, they canโ€™t directly communicate.

Solution?

๐Ÿ‘‰ Move state to Parent.


๐Ÿ›  Example โ€” Without Lifting State

function InputComponent() {
  const [text, setText] = useState("");

  return (
    <input
      value={text}
      onChange={(e) => setText(e.target.value)}
    />
  );
}

function DisplayComponent() {
  return <h2>Text will appear here</h2>;
}

Problem:

  • Input has state

  • Display cannot access it


โœ… Solution โ€” Lift State Up

Step 1 โ€” Move State to Parent

import { useState } from "react";

function Parent() {
  const [text, setText] = useState("");

  return (
    <div>
      <InputComponent text={text} setText={setText} />
      <DisplayComponent text={text} />
    </div>
  );
}

Step 2 โ€” Pass Props to Children

function InputComponent({ text, setText }) {
  return (
    <input
      value={text}
      onChange={(e) => setText(e.target.value)}
    />
  );
}

function DisplayComponent({ text }) {
  return <h2>{text}</h2>;
}

Now:

  • Input updates state in Parent

  • Parent passes updated state to Display

  • Both stay in sync

Clean and predictable ๐ŸŽฏ


๐Ÿง  Mental Model

Instead of:

Sibling โ†” Sibling

Think:

Sibling โž Parent โž Sibling

Data flows down, actions flow up.


๐ŸŽฏ When Should You Lift State Up?

โœ” When multiple components need same data

โœ” When sibling components must stay synchronized

โœ” When building forms

โœ” When managing shared UI state


โŒ When NOT to Lift Too Much

โŒ Donโ€™t move everything to top-level unnecessarily

โŒ Avoid deep prop drilling (use Context if needed)


๐Ÿง  One-Liner

Lifting State Up is the process of moving shared state to the closest common parent so multiple components can access and synchronize it.


๐Ÿ”— How It Connects with Previous Days

โœ” Controlled Components (Day 18)

โœ” Props (Day 6)

โœ” Context API (Day 16)

This is the foundation of React architecture.


โœ… Key Takeaways

โœ” React follows one-way data flow

โœ” Shared state lives in common parent

โœ” Children receive data via props

โœ” Clean communication pattern


๐Ÿ”œ Coming Next

Day 20 โ€” Conditional Rendering (Clean UI Logic Patterns)

Now we refine UI behavior like a real frontend developer ๐Ÿ”ฅ

About the author

  • Frontend Developer | React & JavaScript | Building production-ready web apps Developer with 1.5+ years of experience, currently focused on React, Redux, and full-stack development. Sharing practical tutorials, concepts, and project learnings.

No comments yet. Be the first to comment.

More from this blog