Network Requests
It seems like everywhere you look in various dev communities people will say “of course you should use SWR, react-query, apollo, etc”
Yet, almost every project I’ve come onto has varying degrees of doing vanilla requests, where they just repeat themselves inside of a useEffect hook.
Need to track loading state? Yet another useState and more logic in this duplicated useEffect you find across the codebase.
The thing is, these smart query libraries do a lot more for you. If you want to rebuild them, then go for it. The key thing all of those libraries offer, is a query cache that de-duplicates requests and shares the data between many hooks.
Most of the roll-your-own useEffects I see, have no way to do the same request across components, without passing down props or making a higher order context every single time.
SWR and all the others, have thi…
Keep reading with a 7-day free trial
Subscribe to zach.codes to keep reading this post and get 7 days of free access to the full post archives.