useEffect
useEffect is the one of the commonly used hook in ReactJS
Used to handle side effects in functional components
Syntax
useEffect(effectFn,[])
useEffect(()=>{
console.log("API Calling");
},[]);
useEffect(()=>console.log("API Calling"),[]);
Components lifecycle
Mounting-first time call
Update-to execute again and again
Unmounting-change to another
Types of useEffect
1.empty dependency array-mounting
useEffect(() => {
//Runs only on the first render
}, []);
2.dependency array-update
useEffect(() => {
//Runs on the first render
//And any time any dependency value changes
}, [prop, state]);
3.no dependency array-unmounting
useEffect(() => {
//Runs on every render
});
setInterval
The setInterval() method executes a function repeatedly at a specified interval. We can use the setInterval method in a React component to update the component's state or perform other actions.
Strict Mode
StrictMode is a react component used to identify the potential issues and bug in the react code
If strictmode is ON,the output will execute two times
Top comments (0)