React
React
JAVASCRIPT FUNCTIONALITIES:
Arrow function:
In Es6 version
Ex:
const value = (n1,n2)=>{
return n1+n2;
}
console.log(value(10,20));
Method 2:
const value = (n1,n2)=> n1+n2;
console.log(value(10,20));
IN Es7:
Whereas, in Es 7 we dont nedd any constructor and super constructor with the help
of arrow function we can directly have data in the console and it reduces the code
with easy way to understand it.
Ex:
class human{
name = "yaso";
age = 20;
printname = () => console.log(this.name);
printage = () => console.log(this.age);
}
class person extends human{
name = "yaso krishna";
age = 21;
printname = () => console.log(this.name);
printage = () => console.log(this.age);
}
const persons = new person();
persons.printname()
persons.printage()
output:
"yaso krishna"
21
JS Spread operator:
It is used to expand the data from one set to another with spread operator.
In Array:
without using spread operator:
Ex:
set1 = [1,2,3,4,5];
set2 = [6,7,8,9,10];
console.log(set1);
console.log(set2);
output:
[1, 2, 3, 4, 5]
[6, 7, 8, 9, 10]
with spread operator:
Ex:
set1 = [1,2,3,4,5];
set2 = [...set1,6,7,8,9,10];
console.log(set1);
console.log(set2);
output:
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
In Object:
Here we are using a object with spread operator to expand the data in object, that
copys data from one object to other.
Ex:
set1 = {
name : "yaso",
age : 20
}
set2 = {
...set1,
email : "[email protected]"
}
console.log(set2);
output:
[object Object] {
age: 20,
email: "[email protected]",
name: "yaso"
}
Ex:
values = [10,20,30];
[a,b,c] = values;
console.log(a,b,c);
output:
10
20
30
output:
10
30
In Object:
Ex:
values = {
email : "[email protected]",
age : 20
}
console.log(email)
output:
Reference Error: "email is not defined."
the email is present in the object so we cant directly print the value it gives the
reference error.
To overcome those errors
Ex:
values = {
email : "[email protected]",
age : 20
}
console.log(values.email)
output:
"[email protected]"
Here the values is the reference we need to give to get the output of selected
value in a object and the email is in the values (ie) inside of values object in
above example.
Object Destructuring:
We use a const object to destructure the object and it is based on the names of the
value in a object to assign the values. without any reference we obtain the values
easily.
Ex:
values = {
email : "[email protected]",
age : 20
}
const{email,age} = values;
console.log(email)
console.log(age)
output:
"[email protected]"
20
array(10,20,30,40,50,60)
output:
[10, 20, 30, 40, 50, 60]
If we want the specific array values to be seperated from the variable we choose we
add another variable to store the unwanted data or values.
Ex:
const array = (a,b,...arr) => console.log(a,b);
array(10,20,30,40,50,60)
output:
[10, 20, 30, 40, 50, 60]
[20, 30, 40, 50, 60]
[30, 40, 50, 60]
10
20
JavaScript Arrays:
To enter data into array we use the method "array.push()" and it adds elements at
the "start".
To delete data from the array we use the emthod "array.pop()" and it removes
elements in the array from the "end" (ie) the array last index element will be
removed.
To remove array elements from the starting index of an arrya we use the method
array.shift() so that it will removes the first entered element in the array.
Ex:
1. Push:
output:
[10, 20, 30, 40]
[10, 20, 30, 40, 50]
2. Pop:
output:
[10, 20, 30]
output:
[20, 30, 40]
output:
[10, 20, 40]
iv. To delete a element without its index position but by using the value in to
array.indexOf() method
output:
[10, 30, 40]
-> After complete installation of react app enter npm start to load the web page.
-> In App.js we can make changes that will be reflected in the webportal.
class boiler:
Syntax:
</div>
)
}
}
Example:
syntax:
</div>
)
}
Example:
___________________________________________________________________________________
_________________
Example:
-> props: to puse values from one component to other we use props.
Example: