Skip to Content

Migrating to v4

  • Recommended when updating from @suspensive/react-query v3 to v4.
  • This codemod does not modify package.json. After running it, remove @suspensive/react-query from your dependencies and make sure @suspensive/react-query-4 or @suspensive/react-query-5 is installed.

There are two code-level breaking changes in @suspensive/react-query v4:

  1. The unified package @suspensive/react-query has been removed. All imports must point to the version-specific package @suspensive/react-query-4 or @suspensive/react-query-5.
  2. APIs provided by @tanstack/react-query (such as queryOptions, mutationOptions, etc.) are also removed from @suspensive/react-query-4, 5. These must be imported directly from @tanstack/react-query.
Terminal
npx @suspensive/codemods migrate-to-v4 .

For example:

import { useSuspenseQuery, SuspenseQuery, queryOptions, IsFetching, } from '@suspensive/react-query' import { queryOptions, PrefetchQuery } from '@suspensive/react-query-5' import * as RQ from '@suspensive/react-query' export { queryOptions, QueryClientConsumer } from '@suspensive/react-query'

Transforms into:

import { useSuspenseQuery, queryOptions } from '@tanstack/react-query' import { SuspenseQuery, IsFetching } from '@suspensive/react-query-5' import { queryOptions } from '@tanstack/react-query' import { PrefetchQuery } from '@suspensive/react-query-5' import * as RQ from '@suspensive/react-query-5' export { queryOptions } from '@tanstack/react-query' export { QueryClientConsumer } from '@suspensive/react-query-5'

Version detection

Starting from the current working directory and walking upward, the codemod locates the nearest package.json to determine whether the project depends on v4 or v5 of @tanstack/react-query. The detected major version is used when rewriting @suspensive/react-query to its version-specific source.

If detection fails, the codemod falls back to v5 and prints a warning. To specify the target explicitly, set the SUSPENSIVE_RQ_TARGET environment variable to 4 or 5 before running:

Terminal
SUSPENSIVE_RQ_TARGET=4 npx @suspensive/codemods migrate-to-v4 .

Notes

  • This codemod does not modify package.json. After running it, remove @suspensive/react-query from your dependencies and make sure @suspensive/react-query-4 or @suspensive/react-query-5 is installed.
Last updated on