How to send data using props in react js | How to pass React props to components | React – Passing Data Between Components

Image 174 views

In ReactJS, props (short for properties) are used to pass data from a parent component to a child component. This concept allows components to be reusable and dynamic by feeding them different values. Props work similarly to function parameters β€” they are read-only and help in communication between components.

Let’s say you have a parent component called App and a child component called Greeting. You can pass the user’s name from the parent to the child using props. This enables the child to display dynamic content without managing its own state. Props are one of the core features of React and are essential for building scalable, modular applications.

In this article, we’ll walk through a basic example that demonstrates how to pass and access props in a clean, beginner-friendly way.

πŸ‘‰ Download Free Ebook β†’

πŸ‘‰ Get Free Course β†’

Image

🧩 Example: Passing Name Prop from Parent to Child

πŸ”· Parent Component (App.js)

  1.    import React FROM 'react';
  2. import Greeting FROM './Greeting';
  3.  
  4. FUNCTION App() {
  5.   RETURN (
  6.     <div STYLE={{ fontFamily: 'Arial', padding: '20px' }}>
  7.       <h2>πŸ‘¨β€πŸ’» Welcome TO React Props Demo</h2>
  8.       <Greeting userName="Vijay Kumar" />
  9.     </div>
  10.   );
  11. }
  12.  
  13. export DEFAULT App;

πŸ”Ά Child Component (Greeting.js)

  1.    import React FROM 'react';
  2.  
  3. FUNCTION Greeting(props) {
  4.   RETURN (
  5.     <p>Hello, <strong>{props.userName}</strong>! Have a great DAY ahead 😊</p>
  6.   );
  7. }
  8.  
  9. export DEFAULT Greeting;

 

πŸ“Œ Key Points:

  • Props are passed from parent β†’ child as attributes (userName=”Vijay”)
  • Props are read-only and cannot be modified in the child
  • You access them using props.propertyName

 

FAQ (Frequently Asked Questions)

How to pass data through props in React?

To pass props, add them to the JSX, just like you would with HTML attributes. To read props, use the function Avatar({ person, size }) destructuring syntax. You can specify a default value like size = 100 , which is used for missing and undefined props.

How to pass state as props in React?

Passing state or props from one component to another in React is very simple, especially with the help of event handlers like onClick . Whether you're using class-based components or functional components with hooks, the idea remains the same: state lives in the parent, and data is passed to children via props.

What are props into other components?

Props are arguments passed into React components. Props are passed to components via HTML attributes. props stands for properties.

 
  
πŸ‘‰ Get Free Course β†’ Image

πŸ“Œ Salesforce Administrators

πŸ“Œ Salesforce Lightning Flow Builder

πŸ“Œ Salesforce Record Trigger Flow Builder

πŸ‘‰ Get Free Course β†’

Image

πŸ“Œ Aura Lightning Framework

πŸ“Œ Lightning Web Component (LWC)

πŸ“Œ Rest APIs Integration



Image

Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net