Skip to content

Commit

Permalink
Deploying to deploy from @ 486531f 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
umairwaheed committed Jul 4, 2023
1 parent f802283 commit a068247
Show file tree
Hide file tree
Showing 160 changed files with 500 additions and 192 deletions.
4 changes: 2 additions & 2 deletions 404.html

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion _next/data/Gy2V_1eM8ZT75g8JWp4mD/blogs.json

This file was deleted.

1 change: 0 additions & 1 deletion _next/data/Gy2V_1eM8ZT75g8JWp4mD/index.json

This file was deleted.

1 change: 0 additions & 1 deletion _next/data/Gy2V_1eM8ZT75g8JWp4mD/team.json

This file was deleted.

1 change: 0 additions & 1 deletion _next/data/Gy2V_1eM8ZT75g8JWp4mD/team/bilal-irfan.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pageProps":{"frontmatter":{"title":"RTK Query vs React Query","date":"June 26, 2023","excerpt":"RTK Query and React Query: Powerhouse Solutions for State Management in the React Ecosystem","cover_image":"/images/posts/rtk_query_vs_react_query/RTK-query-header.png","author":"Shameen Jamil"},"slug":"RTK-query-vs-React-query","content":"\n#### What is RTK query?\n\nRTK Query is a powerful data fetching and caching tool. It is designed to simplify common cases for loading data in a web application, eliminating the need to hand-write data fetching & caching logic yourself. RTK Query is an optional addon included in the Redux Toolkit package, and its functionality is built on top of the other APIs in Redux Toolkit. The Redux core has always been very minimal - it's up to developers to write all the actual logic. That means that Redux has never included anything built in to help solve these use cases. The Redux docs have taught some common patterns for dispatching actions around the request lifecycle to track loading state and request results, and Redux Toolkit's createAsyncThunk API was designed to abstract that typical pattern. However, users still have to write significant amounts of reducer logic to manage the loading state and the cached data.\n\n#### Pros of RTK Query:\n\n- <b>_Caching and Normalization:_</b> RTK Query provides built-in caching mechanisms to optimize data fetching. It automatically caches API responses and performs intelligent cache invalidation based on the data dependencies.\n- <b>_Automatic Background Refetching:_</b> RTK Query automatically handles background refetching to ensure your data stays up to date. It can automatically refetch data in the background at configurable intervals or when specific data dependencies change.\n- <b>_Automatic Background Refetching:_</b> RTK Query automatically handles background refetching to ensure your data stays up to date. It can automatically refetch data in the background at configurable intervals or when specific data dependencies change.\n- <b>_Integration with Redux Toolkit:_</b> RTK Query integrates seamlessly with Redux Toolkit, leveraging its store, reducers, and middleware. It follows the principles and patterns of Redux Toolkit, making it easy to adopt and integrate into existing Redux applications.\n\n#### Cons of RTK Query:\n\n- <b>_Limited to use with Redux: _</b> Unlike other data management solutions, RTK Query can only be used in combination with Redux, thus decreasing its overall adaptability.\n\n- <b>_Steep learning curve for developers new to Redux:_</b> For developers who are not already familiar with Redux, learning RTK Query may require a steeper learning curve because it requires an understanding of Redux concepts and patterns.\n\n- <b>_Performance Trade-offs:_</b> RTK Query's automatic caching and background refetching can provide significant performance benefits. However, in certain scenarios with large data sets or complex data relationships, the caching behavior may not be optimal. It's important to carefully configure and test the caching settings to ensure optimal performance for your specific use case.\n\n<b>This is how we create API Service using createAPI hook</b>\n\n import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'\n export const exampleApi = createApi({\n reducerPath: 'exampleApi',\n baseQuery: fetchBaseQuery({ baseUrl: 'https://example.com/api/' }),\n endpoints: (builder) => ({\n getUserByName: builder.query<User, string>({\n query: (name) => `user/all`,\n }),\n }),\n })\n\n#### What is react query?\n\nReact Query is a ReactJS preconfigured data management library which gives you power and control over server-side state management, fetching, and caching of data, and error handling in a simple and declarative way without affecting the global state of your application. React Query handles caching, background updates and stale data out of the box with zero-configuration. There's no global state to manage, reducers, normalization systems or heavy configurations to understand. It comes wired up with dedicated devtools, infinite-loading APIs, and first class mutation tools that make updating your data a breeze.\n\n#### Pros of react query:\n\n- <b>_Simplified Data Fetching:_</b> React Query simplifies the process of fetching and managing data by providing a declarative and intuitive API. It abstracts away the complexities of making network requests, handling loading and error states, and managing data caching and synchronization.\n\n- <b>_Automatic caching:_</b> React Query accelerates data retrieval and optimizes network requests by utilizing an automated caching system.\n\n- <b>_Customization:_</b> React query provides useMutation hook that provides data creation, edition and deletion.\n\n- <b>_Optimized Query Management:_</b> React-query works best with pagination as well as fetching and re-fetching data on background. React Query optimizes query management by providing features like query deduplication, query batching, and smart query invalidation.\n\n#### Cons of react query:\n\n- <b>_Limited functionality:_</b> React Query is focused on fetching and managing data from APIs, so it may not be suitable for more complex state management needs.\n\n- <b>_Smaller community:_</b> Relatively new and may have a smaller community and ecosystem compared to other libraries.\n\nHere is an example of react query:\n\n import { QueryClient, QueryClientProvider, useQuery } from 'react-query'\n const queryClient = new QueryClient()\n export default function App() {\n return (\n <QueryClientProvider client={queryClient}>\n <Example />\n </QueryClientProvider>\n )\n }\n function Example() {\n const { isLoading, error, data } = useQuery('repoData', () =>\n fetch('https://api.github.com/repos/tannerlinsley/react-query').then(res =>\n res.json()\n )\n )\n if (isLoading) return 'Loading...'\n if (error) return 'An error has occurred: ' + error.message\n return (\n <div>\n <h1>{data.name}</h1>\n <p>{data.description}</p>\n </div>\n )}\n\n#### Conclusion:\n\n<br>\nIf your application is more extensive and complex and needs complex state management, RTK is a better choice. If you are building a small, simple application and want to minimize the amount of boilerplate code, React Query may be the way to go. \nReact query is faster than RTK because of it small size but RTK provides excellent features for performance improvement.\nReact Query uses a manual cached key for invalidation and caches by user-defined query keys, while RTK Query uses declarative data invalidations and creates cache keys via endpoints and arguments.\nAt the end, it totally depends on you if you want to use redux go for RTK but if your project is simple go for react query.\n"},"__N_SSG":true}
Loading

0 comments on commit a068247

Please sign in to comment.