Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React UseEffect dependency

if i use useEffect hook as useEffect(() => {…},[depen1, depen2]). will the useEffect run if changes happen in one of the dependency ?

will it run ? or do i need to another useEffect ?

 //GET API NORMAL FOR FIRST LOAD
  useEffect(() => {
    axiosGetCall();
    // eslint-disable-next-line
  }, []);

  //GET API IF DID CHANGE
  useEffect(() => {
    if (didChange === true) {
      // if there is something in details do this
      if (details.email === false) {
        axiosGetCall();
      } else {
        setSearch(true);
        axiosGetCall();
      }
    }
    // eslint-disable-next-line
  }, [didChange]);

  //GET API IF DID Search
  useEffect(() => {
    if (search === true) {
      axiosGetCall();
    }

    // eslint-disable-next-line
  }, [search]);

  //GET API WHEN PAGE CHANGES
  useEffect(() => {
    if (pageChange === true) {
      setValues({ ...values, success: "", error: "" });
      // if there is something in details do this
      if (details.email === false) {
        axiosGetCall();
      } else {
        setSearch(true);
        axiosGetCall();
      }
    }
    // eslint-disable-next-line
  }, [pageChange]);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

useEffect runs if any of the dependencies change. See https://reactjs.org/docs/hooks-effect.html.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading