https://www.youtube.com/watch?v=TNhaISOUy6Q

React Hooks

React has 10 built in hooks.

Screenshot 2023-05-10 at 12.00.42 PM.png

  1. useState:

    1. The React useState Hook allows us to track state in a function component.

      State generally refers to data or properties that need to be tracking in an application.

    2. const [state, setState] = useState(initialValue);

  2. useEffect:

    The useEffect Hook allows you to perform side effects in your components.

    Some examples of side effects are: fetching data, directly updating the DOM, and timers.

    useEffect accepts two arguments. The second argument is optional.

    useEffect(<function>, <dependency>)

    Component LifeCycle:

    1. componentDidMount() // initialised
    2. componentDidUpdate() //state Updated
    3. componentWillUnmount() //Destroyed

    The Below code will call the function alert() when the DOM is rendered

    useEffect(()=>{
    	 alert("Hello Welcome to my website");
    })
    
  3. useContext:

    1. useContext is used to manage the state globally.