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 10 of 59

What Are Props in React and How They Work

Props in React, short for properties, are used to pass data from one component to another, usually from a parent component to a child component. Props make React components dynamic, reusable, and configurable. They allow components to receive values, functions, and even other components as inputs, helping build flexible user interfaces. Props are read-only, which means a component cannot change the props it receives. Understanding how props work is essential for building scalable React applications and for managing data flow effectively between components.

Props are one of the most fundamental concepts in React. They are the primary way to pass data from a parent component to a child component. In React, components are designed to be reusable, and props make this possible by allowing components to receive different data each time they are used.

At a basic level, props work like function arguments. When you call a function, you pass values to it; similarly, when you use a React component, you pass props to it. These props are then available inside the component.

Basic example of props:


function Greeting(props) {
  return <h1>Hello, {props.name}</h1>;
}

function App() {
  return <Greeting name="Akbar" />;
}

In this example, the App component passes a name prop to the Greeting component. The Greeting component receives this data through the props object and uses it to render dynamic content.

Props can also be destructured to make code cleaner and easier to read.

Example using destructuring:


function Greeting({ name }) {
  return <h1>Hello, {name}</h1>;
}

Props are read-only, meaning a child component should never modify the props it receives. This rule ensures predictable data flow and makes applications easier to debug. If a component needs to change data, that data should be managed by state in the parent component.

Props are not limited to strings or numbers. You can pass arrays, objects, functions, and even other components as props.

Example passing different types of props:


function Button({ label, onClick }) {
  return <button onClick={onClick}>{label}</button>;
}

function App() {
  function handleClick() {
    alert("Button clicked");
  }

  return <Button label="Submit" onClick={handleClick} />;
}

Here, a function is passed as a prop, allowing the child component to communicate back to the parent through events. This is a common and powerful pattern in React applications.

A real-world example of props can be seen in form-based applications. A reusable Input component might receive props such as type, value, placeholder, and onChange. The same Input component can then be used for name, email, or password fields by passing different props.

Example:


function Input({ type, placeholder, value, onChange }) {
  return (
    <input
      type={type}
      placeholder={placeholder}
      value={value}
      onChange={onChange}
    />
  );
}

Another important concept related to props is children. The children prop allows components to wrap and display nested content.

Example using children:


function Card({ children }) {
  return <div className="card">{children}</div>;
}

This makes the Card component reusable for different types of content while keeping a consistent layout.

Some important best practices include keeping props simple, avoiding excessive prop drilling, and clearly naming props to reflect their purpose. When many components need the same data, alternative solutions such as context can be used instead of deeply passing props.

In summary, props are the mechanism through which React components communicate and share data. They enable reusability, maintain a clear data flow, and are essential for building dynamic and scalable React applications.