DEV Community

Discussion on: How to Use SWR for Better Data Fetching Approach

 
femincan profile image
Furkan Emin Can • Edited

I just updated the article to make the section clearer.

I'm not agree with you that "In this case I would not worry about cancelling the requests, it just makes things more complicated and has no big advantage."

If the user's network connection is slow, It results in a long loading process. If we cancel the unnecessary requests, the last request completes faster. You can check the updated section for more information.

Thanks for your suggestions.
I think, I can move the fetcher function inside the useRandomQuote hook. It seems more appropriate for me.
I will also update the return statement based on your suggestion.

Thread Thread
 
receter profile image
Andreas Riedmüller

You are right, it can make a difference, especially if the responses are quite big. This would be a nice feature for useSWR

I found that there is a RFC for cancellation with useSWR: github.com/vercel/swr/discussions/... and it has a pull request as well but not reviewed/merged yet.

Maybe it arrives soon.

Thread Thread
 
femincan profile image
Furkan Emin Can

I agree that it would be a nice addition to useSWR. I hope the pull request gets reviewed and merged soon.

I appreciate our discussion and your contributions to the topic. If you have any further questions or thoughts, feel free to share them.