0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
Commit graph

5,005 commits

Author SHA1 Message Date
Kent C. Dodds
1e1e0f67e6
fix: don't schedule garbage collection unnecessarily (#627)
This doesn't actually fix the issue I'm looking into, but I did notice that this timeout is scheduled even when the query is cleared and I *think* it shouldn't be. If we do need to garbage collect something, that should happen in `clear` I think.
2020-06-24 12:19:12 -06:00
David Meade
6922cda1f1
docs(README) typo fix (#623) 2020-06-24 12:14:20 -06:00
Tanner Linsley
0147a8ee1f Update README.md 2020-06-24 12:11:02 -06:00
Tanner Linsley
fd280eca7e fix: query.state.isFetching defaults to the loading status, despite lack of data v2.1.1
Fixes #624
2020-06-24 11:58:59 -06:00
Tanner Linsley
4c741f7499 feat: added queryCache.resetErrorBoundaries v2.1.0
Info can be found in the docs under the `Resetting Error Boundaries` section
2020-06-24 11:45:13 -06:00
Tanner Linsley
8519dd4d6d Merge branch 'master' of https://github.com/tannerlinsley/react-query v2.0.4 2020-06-24 10:39:23 -06:00
Tanner Linsley
c3e42c44af fix(refetchOnWindowFocus): stale queries are no longer refetched 2020-06-24 10:39:15 -06:00
mrroll
bc40a0d5b0
docs: Typo fix (#612) 2020-06-24 10:29:27 -06:00
mick mcmahon
8a401304ca
Update README.md (#613)
Typo - Yay!!!! I contributed!!
2020-06-24 10:29:15 -06:00
Dávid Kizivat
7c32aa4b51
chore(types): Add missing params for mutation types (#617)
* fix(types): Add variable to mutate function

The MutateFunction didn't accept variables when not undifined as expected

* fix(types): Add onMutateValue param to onError mutate option
2020-06-24 10:29:00 -06:00
Tobias Büschel
f17aebad94
docs: correct broken hyperlinks in README.md (#619) 2020-06-24 10:28:25 -06:00
Tanner Linsley
f844de8487 chore: update examples 2020-06-24 10:22:17 -06:00
Tanner Linsley
46b02aae26 Merge branch 'master' of https://github.com/tannerlinsley/react-query 2020-06-24 10:19:23 -06:00
Tanner Linsley
1265818213 Update README.md
Fixes #620
2020-06-24 10:19:13 -06:00
Zade Kaakarni
7d131e6ee3
Update Table of Contents (#607)
* Remove "Manual Querying" section link

* Update TOC

Co-authored-by: Zade Kaakarni <zade.kaakarni@freightverify.com>
2020-06-23 15:58:25 -06:00
Cory House
60c4930d4f
docs: Typo fix (#605) 2020-06-23 12:39:53 -06:00
Augusto
c3424bb481
docs: fix typo (#603) 2020-06-23 09:46:59 -06:00
Tanner Linsley
ebbf1a849b
fix: remove unused wasPrefetched v2.0.3 2020-06-22 20:01:21 -06:00
Tanner Linsley
5ce7b1e8d1 test: Add more query key tests 2020-06-22 17:56:31 -06:00
Tanner Linsley
9c618f37d5 fix(retries): cancel retry timer when query is cleared v2.0.2 2020-06-22 17:43:14 -06:00
Tanner Linsley
8eec19ac65 fix(types): temporarily disable types for 2.0 v2.0.1 2020-06-22 16:00:22 -06:00
Tanner Linsley
84d1a19b02 v2 v2.0.0
(#585)

- Better query invalidation & refetching, less over-fetching
- Simplified dependent query syntax and new `idle` query state
- Multi-instance polling and interval support
- New query status booleans
- Bidirectional Infinite Queries
- Improved mutation lifecycle
- Better test cleanup utils
- Prep for future SSR enhancements

- The booleans `isSuccess`, `isError` `isLoading` and a new one called `isIdle` have been added to the queryInfo object returned by `useQuery` (and friends) and `useMutation`. These are derived safely from the `queryInfo.status` and are guaranteed to not overlap. In most situations, they are easier to use, less typo-prone than status strings and also more terse for determining what to render based on the status of a query.

  ```js
  const queryInfo = useQuery(queryKey, fn)

  return queryInfo.isLoading ? (
    'Loading...'
  ) : queryInfo.isError ? (
    queryInfo.error.message
  ) : (
    <div>{queryInfo.data}</div>
  )
  ```

- `queryCaches` is now exported, which allows you to clean up all query caches that were created. We do this in our own tests when multiple caches are used for testing and to be thorough.

  ```js
  // test.js
  import { queryCaches } from 'react-query'

  afterEach(() => {
    queryCaches.forEach((queryCache) => queryCache.clear())
  })
  ```

- `fetchMore` now supports an optional `previous` option, which will determine if the data you are fetching is should be prepended instead of appended to your infinite list. eg, `fetchMore(nextPageVars, { previous: true })`

  ```js
  const { fetchMore } = useInfiniteQuery(queryKey, fn)

  return (
    <button
      onClick={() => fetchMore(previousPageVariables, { previous: true })}
    />
  )
  ```

- `refetchInterval` can now be changed on the fly. Check out the auto-refetching example to see it in action!
- `invalidateQueries` (previously `refetchQueries`) now has an option called `refetchActive` that when set to `false` will **not** refetch matching queries that are active on the page.
- `makeQueryCache` now accepts an optional configuration object. The `defaultConfig` object is used to override the default query configuration config to use inside of this cache. The `frozen` option if set to `true` will simulate React Query being run on the server, where no queries are cached for privacy and safety concerns. This is the default when using React Query on the server and is optional. You can also set it to `true` on the server and have it work as it would on the client. More information on this coming soon!

BREAKING CHANGE:

- Do you use falsy query keys for dependent queries?
  - The new way to do dependent queries to instead use the `enabled` config flag. You should move your conditions in your key to the `enabled` option
    - Before
    ```js
    useQuery(ready && queryKey, queryFn)
    ```
    - After
    ```js
    useQuery(queryKey, queryFn, { enabled: ready })
    ```
- Do you use functions as queryKeys for dependent queries?
  - If you use functions as query keys that can potentially throw, you should migrate their logic to the `enabled` config option and use optional chaining to cast them to a boolean
    - Before
    ```js
    useQuery(() => ['user', user.id], queryFn)
    ```
    - After
    ```js
    useQuery(['user', user?.id], queryFn, { enabled: user?.id })
    ```
- Do you expect dependent queries to start in the `success` state?

  - Dependent queries now start in a new `idle` state. You should account for this new state where possible. Most rendering logic should still work if you are checking first for the `loading` and `error` states first, then falling back to the "success" state, but still... it's a good idea to do this

    - Before

    ```js
    const { status, data } = useQuery(key, fn)

    return status === 'loading'
      ? 'Loading...'
      : status === 'error'
      ? error.message
      : data
      ? 'The Data'
      : 'Not Ready'
    ```

    - After

    ```js
    const { status } = useQuery(key, fn

    return status === 'idle' ? 'Not Ready' : status === 'loading'
      ? 'Loading...'
      : status === 'error'
      ? error.message
      : 'The Data'
    ```

- Do you use `queryCache.refetchQueries`?
  - `refetchQueries` has been renamed to `invalidateQueries`. You will need make this rename change for your app to continue working propertly. The name change comes due to some differences in what the function does.
    - Before, any queries that matched the `queryKey` used in `refetchQueries(queryKey)` and were also stale, would be refetched... \*\*even queries that were inactive and not rendered on the screen. This resulted in quite a few queries being refetched regardless of their immediate necessity.
    - Now, with `invalidateQueries`, only queries that are actively rendered will be refetched, while any other matching queries will forcefully be marked as stale.
    - This probably won't affect much performance, but should help reduce overfetching out of the box.
- Did you expect `queryCache.refetchQueries` to only refetch stale queries?
  - The new `invalidateQueries` method will **always refetch matching queries that are active**. All other matched queries that are not active will be immediately marked as stale.
- Do you call `queryCache.refetchQueries` with the `force` option?
  - Before, the `force` option was a way to force queries that were not stale to refetch.
  - Now, he new `invalidateQueries` method will **always refetch matching queries that are active** and all other matched queries that are not active will be immediately marked as stale.
- Do you use a global configuration object to configure React Query?
  - Before, the global configuration object was flat:
    ```js
    const globalConfig = {
      suspense,
      useErrorBoundary,
      throwOnError,
      refetchAllOnWindowFocus,
      queryKeySerializerFn,
      onMutate,
      onSuccess,
      onError,
      onSettled,
      retry,
      retryDelay,
      staleTime,
      cacheTime,
      refetchInterval,
      queryFnParamsFilter,
      refetchOnMount,
      isDataEqual,
    }
    ```
  - Now, the global configuration object has 3 parts. The `shared` section, which is a base set of options that are inherited into the next 2 sections, `queries` and `mutations`, each corresponding to the functionality they are used for in React Query:
    ```js
    const globalConfig = {
      shared: {
        suspense,
        queryKeySerializerFn,
      },
      queries: {
        ...shared,
        enabled,
        retry,
        retryDelay,
        staleTime,
        cacheTime,
        refetchOnWindowFocus,
        refetchInterval,
        queryFnParamsFilter,
        refetchOnMount,
        isDataEqual,
        onError,
        onSuccess,
        onSettled,
        throwOnError,
        useErrorBoundary,
      },
      mutations: {
        ...shared,
        throwOnError,
        onMutate,
        onError,
        onSuccess,
        onSettled,
        useErrorBoundary,
      },
    }
    ```
- Do you use "optional query variables" eg. `useQuery(queryKey, optionalVariables, queryFn)` or `useQuery({ variables })`?
  - Optional variables have been removed. They were not used by many and also were unnecessary seeing how you can inline them into your query function
  - Before
    ```js
    useQuery('todos', [optional, variables], queryFn)
    ```
  - After
    ```js
    useQuery('todos', (key) => queryFn(key, optional, variables))
    ```
- Do you use the `globalConfig.refetchAllOnWindowFocus` config option?
  - `refetchAllOnWindowFocus` has been renamed to `refetchOnWindowFocus` to match the option in the configuration object for `useQuery` and friends.
- Do you use the `refetch` function returned by `useQuery` and friends?
  - Previously this `refetch` function would not trigger an actual refetch if the query is not stale.
  - Now, calling this `refetch` will always trigger a refetch, regardless if the query is stale or not.
- Do you expect `prefetchQuery` to skip the first render of `useQuery` instances that render after it?
  - Previously, the first `useQuery` call after a `prefetchQuery` would be skipped all the time.
  - Now, the `staleTime` of a `prefetchQuery` instance is honored. So, if you call `prefetchQuery(key, fn, { staletime: 5000 })`, and then `useQuery(key, fn)` is rendered within those initial 5000 milliseconds, the query will **not refetch in the background, since it is not stale yet**. Likewise, if the stale time has been reached by the time `useQuery(key, fn)` renders, **it will refetch in the background**, since it is stale when `useQuery` mounts/renders.
- Do you use `prefetchQueries`' `throwOnError` or `force` options?
  - `prefetchQuery`'s `throwOnError` and `force` options are now located in a fourth argument, after the query config.
  - Before
    ```js
    prefetchQuery(key, fn, { ...queryConfig, throwOnError: true, force: true })
    ```
  - After
    ```js
    prefetchQuery(key, fn, queryConfig, { throwOnError: true, force: true })
    ```
- Do you call `mutate()` with additional side-effect callbacks? eg. `mutate(vars, { onError, onSuccess, onSettled })`

  - There are no code changes here, however previously, `mutate()`-level side effects would run _before_ side-effects defined in `useMutation`. That order has been reversed to make more sense.
  - Now, the side-effect callbacks in `useMutation` will be fired before their `mutate`-level counterparts.
  - Before

    ```js
    const mutate = useMutation(fn, {
      onSuccess: () => console.log('I will run second'),
    })

    mutate(vars, { onSuccess: () => console.log('I will run first') })
    ```

  - After

    ```js
    const mutate = useMutation(fn, {
      onSuccess: () => console.log('I will run first'),
    })

    mutate(vars, { onSuccess: () => console.log('I will run second') })
    ```

- Do you use `setQueryData` to update multiple queries with a single query key? eg. `setQueryData('todos', newData)` and expect queryKeys `['todos', 1]` and `['todos', 2]` to both get updated?
  - `setQueryData` no longer allows updating multiple queries at once (via prefix matching). If you need to update multiple queries with the same data, you can use the `queryCache.getQueries()` function to match all of the queries you want, then loop over them and use their `query.setData` function to set all of them to the same value.
Co-authored-by: Fredrik Höglund <fredrik.hoglund@gmail.com>
Co-authored-by: Pepijn Senders <PepijnSenders@users.noreply.github.com>
Co-authored-by: Jack <jack.m.ellis@hotmail.co.uk>
Co-authored-by: Jack Ellis <jack.ellis@godaddy.com>
Co-authored-by: Jake Ginnivan <jake@ginnivan.net>
2020-06-22 15:47:18 -06:00
Pepijn Senders
4a37d1b3c4
chore(queryCache): add config parameter to setQueryData call (#587) 2020-06-22 12:06:36 -06:00
Fagner Schwalm
1fc7ed08d1
fix(types): add mutateOptions on MutationFunction (#594) v1.5.9 2020-06-19 14:43:50 -06:00
Tanner Linsley
12665c34e0
Update README.md 2020-06-17 19:39:29 -06:00
Tanner Linsley
6b65427794
Update test-and-publish.yml 2020-06-16 20:11:44 -06:00
Jason O'Neill
06feac8a2d
chore: upgrade dependencies (#583) v1.5.8
* chore: upgrade dependencies

* add workaround for suspense test

* remove size workflow
2020-06-14 19:15:18 -06:00
Jason O'Neill
87008db3a0
fix(types): enable more types for first QueryKey (#577)
* fix(types): enable more types for first QueryKey

* fix(types): enable more types for first QueryKey

* test: update query key test case
2020-06-13 21:13:12 -06:00
Jason O'Neill
21b9b01e5d
fix(types): change return type of removeQueries (#582) 2020-06-13 20:45:49 -06:00
Tanner Linsley
e6d70bd85d Update issue templates 2020-06-11 15:14:06 -06:00
Tanner Linsley
a130369c02 Create config.yml 2020-06-11 15:13:06 -06:00
Avinash
198c97f255
docs: add avinash as a contributor (#573)
Co-authored-by: Avinash <aviesdfsdfsdnash.kumar@instarem.com>
2020-06-10 22:05:45 -06:00
Tanner Linsley
b9690d4efb
fix: force patch release 2020-06-10 10:48:54 -06:00
Benjamin Koltes
f383ae6f88
avoid using externalHelpers in prod (#568) 2020-06-10 10:48:17 -06:00
dependabot[bot]
18933a8ea9
chore(deps): bump websocket-extensions in /examples/suspense (#554)
Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4.
- [Release notes](https://github.com/faye/websocket-extensions-node/releases)
- [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md)
- [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-06-10 10:45:44 -06:00
dependabot[bot]
0ac87eb541
chore(deps): bump websocket-extensions in /examples/playground (#555)
Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4.
- [Release notes](https://github.com/faye/websocket-extensions-node/releases)
- [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md)
- [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-06-10 10:45:38 -06:00
dependabot[bot]
4ce329fd46
chore(deps): bump websocket-extensions in /examples/basic (#556)
Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4.
- [Release notes](https://github.com/faye/websocket-extensions-node/releases)
- [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md)
- [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-06-10 10:45:33 -06:00
dependabot[bot]
023871abfb
chore(deps): bump websocket-extensions in /examples/star-wars (#557)
Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4.
- [Release notes](https://github.com/faye/websocket-extensions-node/releases)
- [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md)
- [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-06-10 10:45:28 -06:00
dependabot[bot]
ab6ebfdef0
chore(deps): bump websocket-extensions in /examples/custom-hooks (#558)
Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4.
- [Release notes](https://github.com/faye/websocket-extensions-node/releases)
- [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md)
- [Commits](https://github.com/faye/websocket-extensions-node/compare/0.1.3...0.1.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-06-10 10:45:22 -06:00
Tanner Linsley
55e4f75954
Delete links-test.yml 2020-06-09 16:19:39 -06:00
Avinash
cf9bd9c167
fix: remove shouldContinueRetryOnFocus on success (#563) v1.5.7
Co-authored-by: Avinash <aviesdfsdfsdnash.kumar@instarem.com>
2020-06-08 12:58:20 -06:00
Daniel Schmidt
94cdeb5a37
fix(types): ReactQueryConfigProvider error type (#560) v1.5.6
This fixes #542 by allowing the `<ReactQueryConfigProvider>` to get the generic error type.
2020-06-08 08:41:53 -06:00
Jack
4261a65fe7
fix(types): default TError type (#547)
after adding the TError generic throughout the codebase, there are now several places where typescript gets cross. QueryOptions<string> for example used to work fine, but now demands that you provide an error type. In other places it's defaulted to Error.
It seems like a logical solution to just add this default everywhere. This means we're being consistent as well as not causing a breaking change.

Co-authored-by: Jack Ellis <jack.ellis@godaddy.com>
2020-06-04 06:54:47 -06:00
Dominik Dorfmeister
b528564f20
fix(types): adapt type definition of dataOrUpdater in setQueryData (#540)
since the updater receives `T | undefined`, it is difficult to construct a `T` from that. oldData can legitimately be `undefined`, but since `getQueryData` can also return `undefined` at any point, it makes more sense to have the updater be able to return `undefined` as well, which also means that `data` itself can be `undefined`
2020-06-02 10:33:17 -06:00
Tanner Linsley
3a589bb50a Merge branch 'master' of https://github.com/tannerlinsley/react-query v1.5.5 2020-06-01 22:44:53 -06:00
Tanner Linsley
4f56c31ba5 fix: useMutation does not await non-promise
Fixes #504
2020-06-01 22:44:47 -06:00
swandir
342c1fba38
fix: do not suspend on subsequent page loads (#531) v1.5.4 2020-06-01 22:40:30 -06:00
Daniel Schmidt
e5f0bb36c6
fix: Add error types (#525)
* Add error types

* Fix indentation
2020-06-01 22:39:12 -06:00
razh
7f3769dea2
docs: fix queries typo (#505) 2020-06-01 22:38:15 -06:00
Kamran Ayub
f6434fa74e
fix(config): Restore previous original config when ReactQueryConfigProvider is unmounted (#429)
* restore default config on cleanup

* Add test for nested configs

* Revert "restore default config on cleanup"

This reverts commit c7647a47a6.

* restore settings

* At least one failing test will pass

* Fix act warning

* Fix other test, copy suspense logic
2020-05-29 21:30:07 -06:00