React Props Usage

Valeria Fischer
2 min readNov 2, 2023

--

In React, props (short for “properties”) are a way to pass data from a parent component to a child component. Props allow you to make your components dynamic and reusable by providing values that can be used within the child component.

In the code above, the App component serves as the parent component and renders the ChildComponent. It passes two props to the ChildComponent: message and number.

Parent Component (App.js):

Child Component (ChildComponent.js):

The ChildComponent is a functional component that receives the props object as a parameter. Inside the component, you can access the values of the props using dot notation, like props.message and props.number.

Now, when you render the App component, it will display the data passed as props in the ChildComponent. The {props.message} and {props.number} expressions in the ChildComponent display the values passed from the parent component.

Here’s how this application works:

When you render the App component, it displays the text "Parent Component" and then renders the ChildComponent.

The ChildComponent displays "Child Component" and then displays the values received via props. In this case, it will show "Received message: Hello from the parent component" and "Received number: 42."

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Valeria Fischer
Valeria Fischer

Written by Valeria Fischer

FullStack Developer / Coder Girl

No responses yet

Write a response