Skip to main content

Topic Learned!

 Topic Learned!

State :


State is updated whenever user want to update it.

Example : ToDo List

Props: 

        Props would be whatever the current state is!

useEffect:


         componentDidMount() {

          // Run This code while the app is loading

        Example fetchUser();

    }

Alternative For componentDidMount():

In functional components 

  //On Every Render
  useEffect(() => {
    console.log("I re-rendered");
  });

Alternative For componentDidMount() but runs only in first Render:

//On First Render/Mount - componentDidMount
  useEffect(() => {
    console.log("Component Is Mounted");
  }, []);

Alternative for componentDidUpdate():

//On First Render + whenever the component changes
  //componentDidUpdate alternative
  useEffect(() => {
    console.log(`The name changed! ${name}`);
    return () => {
      console.log("Component Unmounted!");
    };
  }, [name]);

Alternative for componentDidUnmount()/ Cleanup code to increase apps performance:

// componentWillUnmount alternative
  // Lifecycle func - when component unmounts/cleanup function
  useEffect(() => {
    console.log("Attached listener");
    window.addEventListener("resize", updateWindowWidth);
    return () => {
      console.log("Detached listener");
      window.removeEventListener("resize", updateWindowWidth);
    };

  });

Async Await: 

console.log("This is Async Mastery");

//Async asynchronous the function
async function mihir() {
  console.log("Inside mihir() function");
  //await will ask the execution to stop until the task gets executed
  //In this case fetching the api gets done
  // Go and finish line After Before calling mihir
  const response = await fetch("https://api.github.com/users");
  console.log("Before response");
  const users = await response.json();
  console.log("users resolved");
  return users;
}

console.log("Before calling mihir()");
let a = mihir();
console.log("After calling mihir()");
console.log(a);
a.then((data) => console.log(data));
console.log("Last Line of js file");












Comments

Popular posts from this blog

React Native Full Notes

React Native Full Notes Device Orientation Like Youtube - First Go To App.json and set orientation:: "default"; Then go to project folder and run npm i @react-native-community/hooks import  {  }  from   'expo-status-bar' ; import   React   from   'react' ; import  {  Dimensions ,  StyleSheet ,  SafeAreaView ,  Text ,  View ,  Button ,  Platform ,  StatusBar  }  from   'react-native' ; import  {  useDimensions ,  useDeviceOrientation  }  from   "@react-native-community/hooks" ;   export   default   function   App () {    const  {  landscape  } =  useDeviceOrientation ();    return  (      < SafeAreaView   style = { styles . container } >        < View   style = { {          backg...

Linux Basics Cmd

  Install Package      sudo apt update     sudo apt install discord (Error_?)     sudo apt --fix-broken install  Remove Packages:     sudo apt remove firefox-esr (remove without deleting user data)     sudo apt purge firefox-esr (remove all user data) Update & upgrade :     sudo apt update && sudo apt upgrade     dpkg -l (List insatllled packages)