Saturday, June 6, 2020

React Props

Props stand for "Properties." They are read-only components. It is an object which stores the value of attributes of a tag and work similar

to the HTML attributes. Prop is a way to pass data from one component to other components. It is similar to function arguments. Props are

passed to the component in the same way as arguments passed in a function. Inside the components, we can add an attribute called props. 

Props in functional component

Props in class component

These attributes are available in the component as this.props and can be used to render dynamic data in our render method.
Passing object as props

Since Props are immutable, we cannot modify the props from inside the component. Then how do we maintain component data that may
change over time. We can achieve this using state.

Destructuring Props

It makes it possible to unpack the values from arrays or properties from objects into distinct variables.

Class component

Functional component

No comments:

Post a Comment