6- Props and Components in React framework
What are Components and Props in ReactJS?
It allows passing data from one component to other components.
-------------------------------------------------------------------
Explain props and components in simple terms with example?
Let us consider there is a college .
For example- Harvard and there are informations related to a student.
Lets call it student information and write those information in a certain format.
FIRST METHOD :
Student Information
If we have to create student information for another student all we have to do is change parameters like name, age , college , course and fees .
Name, Age , College , Course and Fees are called properties or props
and student information is called the component of college.
-----------------------------------------------------------------------------------
SECOND METHOD :
props.name= Albert
props.age= 26
props.college= Harvard
props.course= Physics
props.fees= 20,000
Student Information
You can see in first method you have to basically directly write each value(like name) into the code.
So if you want to change name then you have to change name everywhere name is written.
But,In second Method when you declare a variable like {props.name} then you only change value where variable is set and changes are made wherever that variable exists.
Student Information is component
AND
Name is prop
Comments
Post a Comment