Skip to main content

Migrating from RTK Query

Quantum Query is designed to be simpler and lighter than RTK Query. Here is how concepts map.

Core Concepts

RTK QueryQuantum Query
createApiNot needed. Just use queryCache or hooks directly.
endpointsJust async functions.
useGetXQueryuseQuery({ queryKey: ['x'], queryFn: ... })
tagTypes / providesTagsqueryKey (arrays)
invalidatesTagsqueryCache.invalidate(['key'])

Example Refactor

RTK Query:

const api = createApi({
baseQuery: fetchBaseQuery({ baseUrl: '/api' }),
endpoints: (builder) => ({
getTodo: builder.query({
query: (id) => `todo/${id}`,
}),
}),
});

Quantum Query:

// Define a fetcher
const fetchTodo = (id) => fetch(`/api/todo/${id}`).then(r => r.json());

// Use it
const { data } = useQuery({
queryKey: ['todo', id],
queryFn: () => fetchTodo(id)
});

Why Switch?

  • Bundle Size: Save ~50KB (No Redux required).
  • Flexibility: Use any fetcher (fetch, axios, ky).
  • Simplicity: No boilerplate "slice" setup.