gdirk07 / PokemonChecker

Playing around with APIs
https://gdirk07.github.io/PokemonChecker/
0 stars 0 forks source link

Memoized function and factory declarations #74

Closed jeremy-jtlo closed 2 years ago

jeremy-jtlo commented 2 years ago

I noticed after running the app that we were doing duplicate calls for all Pokemon + images we were rendering. The calls were coming from the service, but ultimately, it was the PokemonDisplay.tsx file that was trying to re-fetch the data all the time.

At its core, I believe it was because of how we implemented useEffect in #70 . When the hook was first put in, there were no dependencies fed to it. This will cause it to default to the behaviour of running useEffect every time the component renders.

I've fed the appropriate dependencies to useEffect, and wrapped some declarations in useCallback and useMemo for performance reasons. Details will be annotated in the file.