Skip to content

SayamDev/props

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

-Can pass props downwards - like a tree -Cannot pass props upwards to parents. -Props are read only, therefore cannot modify the prop in the child component, if we want to modify it, have to modify it in the top component first using state

What I have done in App.js is created a component called Product which will have 3 props = name, description, price. And what i have done in the Product.js is , first of all created a component called Product and passed props into the parameter and also passed the 3 props i created in the App.js Here image

With this now, i can use the one component and use it over and over again all over the application image

We can also object desctrucutre the object and grab the element directly and then rerender it image

And now what we need to do now is create a sub component called ItemDescription and pass the props down to that one (remember tree structure can only pass down prop)

Therefore I created a sub component called ItemDescription and i am only passing the name and the description since i want the name & the description to appear on the product image

Here i have passed the props into the ItemDescription component in the ItemDescription.js but havent passed the props in the Product.js image

Passed the 1st prop into the image

2nd prop passed from the 2nd component image

The price prop was not used in the ItemDescription sub component, so we just called it like this image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published