novuhq / hacksquad-website

Contribute code, meet community members, participate in workshops, and win more SWAG 🚀
https://hacksquad.dev
MIT License
255 stars 190 forks source link

refactor: double nested await #62

Closed andrewdoro closed 1 year ago

andrewdoro commented 1 year ago

This is mostly about best practices (double nested await calls don't look great). Also I've found this great article about using async/await in useEffect. https://devtrium.com/posts/async-functions-useeffect https://github.com/novuhq/hacksquad-website/blob/ac8591b33959170e63b14bf13fc0b89b31e608f2/src/pages/myteam.jsx#L9-L19

I think changing to this would be much better

   useEffect(() => {
    const getTeam = async () => {
      const data = await fetch(`/api/team`, {
        credentials: 'include',
      });
      const json = await data.json();
      setInfo(json);
    };
    getTeam();
  }, []);
nevo-david commented 1 year ago

I mean, it's the same thing. If you think that is necessary, go to it!