![]() |
VOOZH | about |
ReactJS is a powerful library that helps developers build interactive user interfaces by breaking them into reusable components. One of the essential features of React is the ability to pass data between components using props. In React, props allow parent components to send data or functions to child components.
Step 1: To create a new React app, run the following command in your terminal to start a new React app.
npx create-react-app testappStep 2: Step 2: Move to the project folder:
cd testappStep 3: Create a components folder inside the src directory, and within that folder, create a new component file called Child.js. This will serve as the child component where we will receive the props.
Project Structure
When users pass the data from parent to child using the class components, they can access inside the child component using 'this.props.property_name'.
Steps:
Example: Passing props from parent to child component in react usign class components App.js and child.js
Step to run the application: Open the terminal and type the following command.
npm startOutput: This output will be visible on http://localhost:3000/ in the Web browser.
To access properties from parent to child using a functional component, users don't need to use 'this.props' like class components. Users can access props value by writing variable names only.
Steps:
Example:
Step to run the application:
Step 1: Open the terminal and type the following command.
npm startOutput: This output will be visible on http://localhost:3000/ in the Web browser.
👁 Screenshot-from-2023-10-10-11-41-52