Free ATS Friendly Resume Builder Online

Create Your Resume

Resume Builder

Resume Maker

Resume Templates

Resume PDF Download

Create Your Resume is a free online resume builder that helps job seekers create professional, ATS friendly resumes in minutes. Easily build, customize, and download modern resume templates in PDF format.

Our resume maker is designed for freshers and experienced professionals looking to create job-ready resumes. Choose from multiple resume templates, customize sections, and generate ATS optimized resumes online for free.

Create resumes for IT jobs, software developers, freshers, experienced professionals, managers, and students. This free resume builder supports CV creation, resume PDF download, and online resume editing without signup.

Back to React Js
Lesson 24 of 59

What Are Component Communication Patterns and Presentational vs Container Components in React

Component communication patterns in React define how data and events flow between components to keep the UI consistent and interactive. These patterns include parent-to-child, child-to-parent, and sibling communication. Presentational and container components are a design approach that separates UI rendering from business logic. Presentational components focus only on how things look, while container components manage data, state, and behavior. Understanding these concepts helps developers write cleaner, more maintainable, and scalable React applications with clear separation of concerns.

In React applications, components rarely work in isolation. They often need to communicate with each other to share data, trigger actions, or respond to user interactions. Component communication patterns define how this data flow is structured and maintained.

Component Communication Patterns

The most common communication pattern in React is parent-to-child communication. In this pattern, data is passed from a parent component to a child component using props. This is the default and most straightforward way to share data.

Example:


function Child({ message }) {
  return <p>{message}</p>;
}

function Parent() {
  return <Child message="Hello from Parent" />;
}

Another important pattern is child-to-parent communication. Since React follows a unidirectional data flow, children cannot directly change parent state. Instead, the parent passes a function to the child, and the child calls that function when an event occurs.

Example:


function Child({ onSend }) {
  return <button onClick={() => onSend("Data from Child")}>Send</button>;
}

function Parent() {
  function handleData(data) {
    console.log(data);
  }

  return <Child onSend={handleData} />;
}

Sibling communication occurs when two components need to share data but are not directly related. This is handled by lifting the shared state to their closest common parent and passing data down as props.

Example:


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

function Display({ value }) {
  return <p>{value}</p>;
}

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

  return (
    <>
      <Input onChange={setText} />
      <Display value={text} />
    </>
  );
}

These patterns ensure predictable data flow and clear ownership of state.

Presentational vs Container Components

Presentational and container components represent a design pattern used to separate concerns in React applications.

Presentational components focus purely on how the UI looks. They receive data via props and render UI elements. They do not manage state or contain business logic.

Example of a presentational component:


function UserCard({ name, email }) {
  return (
    <div>
      <h3>{name}</h3>
      <p>{email}</p>
    </div>
  );
}

This component is reusable, easy to test, and unaware of where the data comes from.

Container components focus on how things work. They manage state, fetch data, handle events, and pass data down to presentational components.

Example of a container component:


function UserContainer() {
  const [user, setUser] = React.useState({
    name: "Akbar",
    email: "akbar@email.com"
  });

  return <UserCard name={user.name} email={user.email} />;
}

Here, the container handles the data and logic, while the presentational component handles the UI.

Real-World Scenario

In a real-world application such as a dashboard or form-based system, container components handle API calls, validation, and state updates, while presentational components render forms, tables, or cards. This separation improves readability, testing, and maintainability, especially in large codebases.

Important Notes and Best Practices

Not every project requires strict separation into presentational and container components, especially in small applications. However, this pattern becomes valuable as applications grow. Modern React with Hooks often combines logic and UI in functional components, but the conceptual separation is still useful for structuring code.

In summary, component communication patterns define how data flows between components, while presentational and container components help separate UI from logic. Together, these concepts form the foundation for building clean, scalable, and maintainable React applications.