React.js – Props

Hey guys 👋🏻,
In this post, let us cover what actually are props in React.js

For this post we will first understand Props
âś” What is Props ?
âś” Understanding Props
âś” Accessing Props in Functional and Class based Components
âś” Examples of Props


This content originally appeared on DEV Community and was authored by The Nerdy Dev

Hey guys 👋🏻,
In this post, let us cover what actually are props in React.js

For this post we will first understand Props
âś” What is Props ?
âś” Understanding Props
âś” Accessing Props in Functional and Class based Components
âś” Examples of Props

Image description

Introduction to Props

Props are used to make components configurable, dynamic and flexible. Every HTML element as we know has some attributes like input element has value, placeholder etc. It is dynamic content that you can configure from outside.

Understanding Props

Our components which are customized HTML elements can also be passed some arguments in form of attributes known as props so as to configure just like any other HTML element is configured and it is the parent component that passes these arguments to the child component.

Every child component receives props as an argument that is passed to it by React which is an object that holds the arguments that the parent component passed to the child component and that object is known as props. props basically means all the properties that a component is receiving from outside.

When using functional components, you can access the props using the below syntax :

props.<propName>

When using class components, you can access the props using the syntax :

this.props.<propName>

EXAMPLES

Passing a prop of brand to the Computer component :

Image description

Defining our Computer component which receives the brand prop.

Image description

So this is it for this article. Thanks for reading.
Don't forget to leave a like if you loved the article. Also share it with your friends and colleagues.

Alt Text


This content originally appeared on DEV Community and was authored by The Nerdy Dev


Print Share Comment Cite Upload Translate Updates
APA

The Nerdy Dev | Sciencx (2021-11-17T12:09:38+00:00) React.js – Props. Retrieved from https://www.scien.cx/2021/11/17/react-js-props/

MLA
" » React.js – Props." The Nerdy Dev | Sciencx - Wednesday November 17, 2021, https://www.scien.cx/2021/11/17/react-js-props/
HARVARD
The Nerdy Dev | Sciencx Wednesday November 17, 2021 » React.js – Props., viewed ,<https://www.scien.cx/2021/11/17/react-js-props/>
VANCOUVER
The Nerdy Dev | Sciencx - » React.js – Props. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/17/react-js-props/
CHICAGO
" » React.js – Props." The Nerdy Dev | Sciencx - Accessed . https://www.scien.cx/2021/11/17/react-js-props/
IEEE
" » React.js – Props." The Nerdy Dev | Sciencx [Online]. Available: https://www.scien.cx/2021/11/17/react-js-props/. [Accessed: ]
rf:citation
» React.js – Props | The Nerdy Dev | Sciencx | https://www.scien.cx/2021/11/17/react-js-props/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.