MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Lifting State Up Between Siblings0%
Study Materials
React.js for BeginnersProgress 0%
1.1Why React and Single-Page Architecture1.2Setting Up Modern React with Vite1.3React Project Directory Structure and Entry Points1.4Virtual DOM and React Render Cycle Explained
4.1Introduction to Component State4.2The useState Hook Fundamentals4.3Updating State and Immutable Updates4.4Lifting State Up Between Siblings
HomeTutorialsReact.js for BeginnersLifting State Up Between Siblings
Handling Synthetic Events in React

Lifting State Up Between Siblings

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. The Sibling Communication Problem

In React's unidirectional data flow, data flows strictly top-down from parent to child. Sibling components cannot directly communicate with one another or pass state horizontally.

Consider a common scenario:

  • Component A: An AccordionHeader or a SearchInput
  • Component B: An AccordionContent or a SearchResultsList
1 Parent Container
2 ┌───────┴───────┐
3 ▼ ▼
4Component A Component B
5(Cannot send data directly across to sibling!)

If Component A holds state in its own local useState, Component B has no way of reading that state or reacting to its changes.

2. The Solution: Lifting State Up

To share state between two or more sibling components:

  1. 1
    Identify the closest common parent component in the tree.
  2. 2
    Move the state up into that common parent.
  3. 3
    Pass the state down to the consuming child as a read-only prop.
  4. 4
    Pass an event handler callback down to the modifying child so it can request state changes in the parent.
1 Common Parent
2 [holds state + updater function]
3 │ │
4(passes state) │ │ (passes state & callback)
5 ▼ ▼
6 Component A Component B

3. Step-by-Step Code Walkthrough

Step 1: Create the Child Components

Child 1 (SearchInput) receives the current search term and a callback:

1export function SearchInput({ query, onQueryChange }) {
2 return (
3 <div className="search-box">
4 <input
5 type="text"
6 placeholder="Filter courses..."
7 value={query}
8 onChange={(e) => onQueryChange(e.target.value)}
9 />
10 </div>
11 );
12}

Child 2 (SearchResults) receives the filtered list:

1export function SearchResults({ results }) {
2 if (results.length === 0) {
3 return <p className="empty-msg">No matching courses found.</p>;
4 }
5 
6 return (
7 <ul className="results-list">
8 {results.map((course) => (
9 <li key={course.id}>{course.title}</li>
10 ))}
11 </ul>
12 );
13}

Step 2: Lift State to the Common Parent

The parent component (CourseDirectory) owns the query state and coordinates data flow:

1import React, { useState } from 'react';
2import { SearchInput } from './SearchInput';
3import { SearchResults } from './SearchResults';
4 
5const ALL_COURSES = [
6 { id: 1, title: 'React.js for Beginners' },
7 { id: 2, title: 'JavaScript Mastery' },
8 { id: 3, title: 'Django Backend Architecture' }
9];
10 
11export default function CourseDirectory() {
12 // State lifted to common parent
13 const [query, setQuery] = useState('');
14 
15 // Derived state: calculate filtered results during render
16 const filteredCourses = ALL_COURSES.filter((c) =>
17 c.title.toLowerCase().includes(query.toLowerCase())
18 );
19 
20 return (
21 <div className="directory-container">
22 <h2>MSK Course Search</h2>
23
24 {/* Passes state and updater callback to Child 1 */}
25 <SearchInput query={query} onQueryChange={setQuery} />
26
27 {/* Passes derived data to Child 2 */}
28 <SearchResults results={filteredCourses} />
29 </div>
30 );
31}

4. Single Source of Truth

Lifting state up establishes a single source of truth. Instead of trying to keep local copies of data synchronized across multiple sibling components, one component acts as the authority. This architectural discipline prevents out-of-sync UI states and simplifies debugging.


Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why can't two sibling components in React share state directly with each other?
Question 2
What is the recommended technique when two sibling components need access to the same state?
Question 3
How does a child component trigger a state update in its parent component?
Question 4
What is the concept of a "Single Source of Truth" in React state architecture?
Question 5
What is "derived state" in the context of lifting state up?
Next Lesson

Handling Synthetic Events in React

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Updating State and Immutable UpdatesHandling Synthetic Events in React

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext