useEffect in React

  1. The useEffect hook allows you to perform side Effects in your components.
  2. Some Examples of side effect are : Fetching Data, directly updating the form, and timers.
  3. useEffect accepts two arguments, The second argument is optional = useEffect(<function>, <dependency>)

Example 1

1. No dependency passed:

1 useEffect(() => {
2    //Runs on every render
3  });

Example 2

2. An empty array:

1useEffect(() => {
2    //Runs only on the first render
3  }, []);

Example 3

3. Props or state values:

1useEffect(() => {
2    //Runs on the first render
3    //And any time any dependency value changes
4  }, [prop, state]);
❤️ Thank You 🙏
Pranam