1hanzla100 / developer-portfolio

Software Developer Portfolio Template built with react.js and next.js bootstrap that helps you showcase your work and skills as a software developer.
https://developer-portfolio-1hanzla100.vercel.app/
Apache License 2.0
712 stars 457 forks source link

Avoid Using usestate hook without cleanup or dependency list #1

Closed 0xsonu closed 3 years ago

0xsonu commented 3 years ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'GithubProfile.jsx'
  2. look for useEffect which is running in an infinite loop

Expected behavior It should be run in controlled way

Solution create a variable query and assign the get query to it and then pass it in getData function as an argument and also pass it as useffect dependency list

i.e:

const quary = `https://api.github.com/users/${openSource.githubUserName}`;
  const [prof, setProf] = useState({});
  async function getProfileData(q) {
    await get(q)
      .then((res) => setProf(res.data))
      .catch((err) => console.log(err));
  }
  useEffect(() => {
    getProfileData(quary);
  }, [quary]);