Try catch is an important wrapper as it avoids the termination of the app if there is an exception during data fetching, best example would be data fetching in next js, If you don't use try catch and an exception occurs, your webpage will crash
I'm not against generic try..catch. I'm against throwing an error when a non-OK response is received via fetch() because then you are forced to write an extra try..catch.
This article is focusing on how we could handle the api like fetch method for beginners, axios method and react useEffect for intermediate and React query for pro
It's not possible to go in depth about these covering all the concepts in detail in a single article.
You could refer the official documentation for these concepts to learn more about other implementations like pagination, infinite scrolling, retries, dynamic data fetching, refetch on operation, etc.
Developer from India. I build open source tools and AI agents. Made OpenFile, 360+ free file tools that run in your browser. github.com/aniruddhaadak80
Location
India
Work
Developer building open source tools and AI agents
Gopi Krishna Suvanam is an entrepreneur and author of a book on economics. He has co-founded G-Square Solutions, offering AI and analytics services. He is passionate about decentralization and AI.
I'm on a quest against
if (!response.ok) throw....The Ugly Truth: All Popular fetch() Wrappers Do It Wrong
Discover the reality behind axios, ky and popular data-fetching NPM packages and how to replace them.
Try catch is an important wrapper as it avoids the termination of the app if there is an exception during data fetching, best example would be data fetching in next js, If you don't use try catch and an exception occurs, your webpage will crash
I'm not against generic try..catch. I'm against throwing an error when a non-OK response is received via fetch() because then you are forced to write an extra try..catch.
Yeah, that is just an example, in a real world project, we will be adding an error state and a UI for that exception.
I thought this article was about going pro! Anyway, what about retry logic, have you seen that implemented in the real world?
@z2lai are you asking the author or me? Apologies. The notification showed up in my feed. The author, right?
This article is focusing on how we could handle the api like fetch method for beginners, axios method and react useEffect for intermediate and React query for pro
It's not possible to go in depth about these covering all the concepts in detail in a single article.
You could refer the official documentation for these concepts to learn more about other implementations like pagination, infinite scrolling, retries, dynamic data fetching, refetch on operation, etc.
Incredibly helpful, thank you!
Nice, this is a great overview. Pretty sure I have used each method in different projects.
thanks for the lovely introduction..