-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learn React with TypeScript
By :

In this chapter, we started by exploring the use of the useEffect
Hook for client-side data fetching and how challenging writing robust code is. We quickly switched to using TanStack Query and experienced how it simplified the code and enabled features like the retrying of a data fetch when it errors. We experienced how it automatically refreshed data when our app’s browser tab regained focus – something not possible with server-side data fetching.
We learned that using a Server Function has some downsides for client-side data fetching, such as using an HTTP POST request rather than an HTTP GET. We switched to using a Next.js Route Handler because of the downsides.
We learned that Server Functions are ideal for mutating data because of their simplicity and type safety. We used a Server Function in our app to add a new blog post to our database. We used TanStack Query with a Server Function for mutating data and learned that the TanStack Query cache needs...