0% found this document useful (0 votes)
15 views2 pages

Assignment 5

Uploaded by

sarimane07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Assignment 5

Uploaded by

sarimane07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1) Study on change property in html

In React.js, you can handle changes to a component's property using lifecycle methods or React
hooks. The specific approach depends on whether you are working with class components or
functional components.
For Class Components:
componentWillReceiveProps(nextProps): This lifecycle method is called when the component
receives new properties.

componentWillReceiveProps(nextProps) {
if (this.props.someProp !== nextProps.someProp) {
// Handle the change in properties here
}
}
componentDidUpdate(prevProps, prevState): This lifecycle method is called after the component
updates and receives new properties or state

componentDidUpdate(prevProps) {
if (this.props.someProp !== prevProps.someProp) {
// Handle the change in properties here
}
}

For Functional Components (using React hooks):


useEffect: You can use the useEffect hook with the dependency array to monitor changes in specific
properties. Whenever the specified properties change, the effect callback is triggered.

useEffect(() => {
// Handle the change in properties here
}, [someProp]);

2) explain default export keyword with code


The export default syntax is used to export a single value or module as the default export from a file.
This default export can then be imported and assigned any name in the importing file.
Here's an example to illustrate the usage of export default in React.js:
// MyComponent.js
import React from 'react';

const MyComponent = () => {


// Component logic here
return <div>Hello, world!</div>;
};

export default MyComponent;


In this example, we have a file named MyComponent.js that defines a functional component called
MyComponent. The export default keyword is used to export MyComponent as the default export
from the file.
3) code to write map and filter function

//MAP FUNCTION
const square=(n1)=>{
return n1*n1;
}

const arr=[1,2,3,4,5,6,7,8,9,10];
const squaredArr= arr.map(square); //map is higher order func and sqaure is
callback passed ass arg
console.log(squaredArr);

const cube=(n1)=>{
return n1*n1*n1;
}
const array=[1,2,3,4,5];
const cubedArr=arr.map(cube);
console.log(cubedArr);

//FILTER FUNCTION
const filterodd=(num)=>{
if(num%2==0){
return true
}
else{
return false
}
}

const arr=[1,2,3,4,5,6,7,8,9,10];
const filteredArr= arr.filter(filterodd);//parameter
console.log(filteredArr);

const greaterThan=(n)=>{
if(n<6){
return false
}
else{
return true
}
}
const arr3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const greaterArr = arr.filter(greaterThan);//parameter
console.log(greaterArr);

You might also like