React JS useEffect

  • useEffect is a hook in React that lets you run some code after rendering
  • Some of side effects  it can perform are: fetching data,  making API calls, updating the DOM, and setting up an event listener.

useEffect accepts two arguments. The second argument is optional.

useEffect(<function>, <dependency>)

3 types of syntax possibilities.

1. It will run every-time render get calls

useEffect(() => {

        2. It will run on first render

        useEffect(() => {
        }, [ ] )

        3. It will render whenever count changes

        useEffect( () =>{

        Usage Example:

        Leave a Comment

        Your email address will not be published. Required fields are marked *

        Scroll to Top