{"dist":{"shasum":"134c70ddc91d4b0e53bfded82919498bd3366688","tarball":"https://registry.npmjs.org/react-query/-/react-query-0.0.13.tgz","fileCount":9,"integrity":"sha512-IF/mFmnhT2NBf4FfTOXbxCOJZqtrFP3HjJ7OHdOBPvGYRd083/CArbmi0N0y/DrjukSvQOqSSD4mhQeuW9g17A==","signatures":[{"sig":"MEQCIHaXG1ZLOczDI2MkxwGm26T5uEuVwpcXSTdhXNFmeOa3AiAlxWrJVoRfPayF/DTQoEz17GJ6WjNjRw9B1D42u5Z1/w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":156925,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdvwraCRA9TVsSAnZWagAAAcUQAI5uv4i5dJGdDZUJD1yb\nmJ7XWVDfuLoxckuR1q3fy7TuDBIn/CLd9qDKLt7g44LpLXN1TJ6UAeFsxkH6\n0FqgQOOzTbQognagscrLjRho3h6uVb+sTEnZmUmN2wVu2zrwjz6dYEwfWjmm\nP8/mAlDd2ps48lAqAdFaG1uy+QF5MGUdM85jWMIuqMbg4A5SFXqvAWMrIhPC\nadjMGmZh8n/5W7ayBViFeNMKAlx0C8n7nj2szFWSl+QY13CksjIU6AoRi2c1\nlxWLAQDXeDixgooWj2ujT6q/eY4GnR0130hQcLBOVhyy0ej5sSS6xf9Gtld1\nEgS9Wvid7h64egPi/PgoiCnqzH5HKSs5/1qk+OXnldtINKZk2EzWAYVgFyUz\nVuZlJS5q+2ZrmfWuGHH+kJrqvxpRv3+zjUc0BE2cpL7fOD9xKl1OlqM1qeXE\n4BkhpUJ2CH2Kv6d8jPNBxLi1MxZQ5zHOHlgtpvknROCDLx/wB+H3HCSvArhN\nYV9BLvmTw55ClrT4yfF5S/3B05tqHK2PH2RwBV2hHC/XL7jo4kASpvT3j8bC\nEswphDxkKFt8bZ0ycFItP5Ci1ESW+8g8eKx9mdNgKf6GzTEJotJ+bbCPuBV/\nxiopip+PSF45J1z7Mlmtz4N6iVQn9J18M3vi6JJzjBzKmGRhrPZoCL+dZng0\n5mmm\r\n=BIkG\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","name":"react-query","author":{"name":"tannerlinsley"},"module":"dist/index.es.js","readme":"![React Query Header](https://github.com/tannerlinsley/react-query/raw/master/media/header.png)\n\n<img src='https://github.com/tannerlinsley/react-query/raw/master/media/logo.png' width='300'/>\n\nHooks for managing, caching and syncing asynchronous and remote data in React\n\n<!-- <a href=\"https://travis-ci.org/tannerlinsley/react-query\" target=\"\\_parent\">\n  <img alt=\"\" src=\"https://travis-ci.org/tannerlinsley/react-query.svg?branch=master\" />\n</a> -->\n<a href=\"https://npmjs.com/package/react-query\" target=\"\\_parent\">\n  <img alt=\"\" src=\"https://img.shields.io/npm/dm/react-query.svg\" />\n</a>\n<a href=\"https://bundlephobia.com/result?p=react-query\" target=\"\\_parent\">\n  <img alt=\"\" src=\"https://badgen.net/bundlephobia/minzip/react-query\" />\n</a>\n<a href=\"https://spectrum.chat/react-query\">\n  <img alt=\"Join the community on Spectrum\" src=\"https://withspectrum.github.io/badge/badge.svg\" />\n</a>\n<a href=\"https://github.com/tannerlinsley/react-query\" target=\"\\_parent\">\n  <img alt=\"\" src=\"https://img.shields.io/github/stars/tannerlinsley/react-query.svg?style=social&label=Star\" />\n</a>\n<a href=\"https://twitter.com/tannerlinsley\" target=\"\\_parent\">\n  <img alt=\"\" src=\"https://img.shields.io/twitter/follow/tannerlinsley.svg?style=social&label=Follow\" />\n</a>\n<br />\n<br />\n<a href=\"https://patreon.com/tannerlinsley\">\n  <img width=\"180\" alt=\"\" src=\"https://raw.githubusercontent.com/tannerlinsley/files/master/images/patreon/become-a-patron.png\" />\n</a>\n\n## Quick Features\n\n- Transport, protocol & backend agnostic data fetching\n- Auto Caching + Background Refetching (stale-while-revalidate model)\n- Auto Refetch (on-window-focus, when-stale)\n- Parallel + Dependent Queries\n- Mutations\n- Multi-layer Cache + Garbage Collection\n- 4kb (minzipped)\n\n## The Challenge\n\nTools for managing async data and client stores/caches are plentiful these days, but most of these tools:\n\n- Duplicate unnecessary network operations\n- Force normalized or object/id-based caching strategies on your data\n- Don't invalidate their caches often enough or don't ship with good defaults or mechanisms to do so\n- Don't perform optimistic updates, or require setup to know when to perform them\n- Because of this ☝️, they require imperative interaction to invalidate or manage their caches\n\n## The Solution\n\nReact Query exports a set of hooks that attempt to address these issues. Out of the box, React Query:\n\n- Flexibly dedupes simultaneous requests to assets\n- Automatically caches request responses\n- Automatically invalidates stale cache data\n- Optimistically updates stale requests in the background\n- Optimistically seeds new requests from stale data while fetching new dat\n- Supports automatic retries and exponential or custom back-off delays\n- Provides both declarative and imperative API's for:\n  - Manually invalidating requests\n  - Atomically updating cached responses\n\n## Hat Tipping\n\nA big thanks to both [Draqula](https://github.com/vadimdemedes/draqula) for inspiring a lot of React Query's original API and documentation and also [Zeit's SWR](https://github.com/zeit/swr) and it's creators for inspiring even further customizations and optimizations. You all rock!\n\n## Demos\n\n- [A contrived CodeSandbox example](https://codesandbox.io/s/github/tannerlinsley/react-query/tree/master/example)\n\n# Documentation\n\n## Installation\n\n```bash\n$ npm i --save react-query\n# or\n$ yarn add react-query\n```\n\n## Queries\n\nTo make a new query, call the `useQuery` hook with:\n\n- A **unique key for the query**\n- An **asynchronous function (or similar then-able)** to resolve the data\n\n```js\nconst info = useQuery('todos', fetchTodoList)\n```\n\nThe **unique key** you provide is used internally for refetching, caching, deduping related queries.\n\nThis key can be whatever you'd like it to be as long as:\n\n- It changes when your query should be requested again\n- It is consistent across all instances of that specific query in your application\n\nThe query `info` returned contains all information about the query and can be easily destructured and used in your component:\n\n```js\nfunction Todos() {\n  const { data, isLoading, error } = useQuery('todos', fetchTodoList)\n\n  return (\n    <div>\n      {isLoading ? (\n        <span>Loading...</span>\n      ) : error ? (\n        <span>Error: {error.message}</span>\n      ) : data ? (\n        <ul>\n          {data.map(todo => (\n            <li key={todo.id}>{todo.title}</li>\n          ))}\n        </ul>\n      ) : null}\n    </div>\n  )\n}\n```\n\n### Query Keys\n\nSince React Query uses a query's **unique key** for essentially everything, it's important to tailor them so that will change with your query requirements. In other libraries like Zeit's SWR, you'll see the use of URL's and GraphQL query template strings to achieve this, but we believe at scale, this becomes prone to typos and errors. To relieve this issue, you can pass a **tuple key** with a `string` and `object` of variables to deterministically get the the same key.\n\n> Pro Tip: Variables passed in the key are automatically passed to your query function!\n\nAll of the following queries would result in using the same key:\n\n```js\nuseQuery(['todos', { status, page }])\nuseQuery(['todos', { page, status }])\nuseQuery(['todos', { page, status, other: undefined }])\n```\n\n> Note: To aid you in your quest, if a query key is used that contains a `?` (like `todos?page=${page}&status=${status}`), you will see a gentle console warning to use the above format instead.\n\n### Query Variables\n\nTo use external props, state, or variables in a query function, pass them as a variables in your query key! They will be passed through to your query function as the first parameter.\n\n```js\nfunction Todos({ status }) {\n  const { data, isLoading, error } = useQuery(\n    ['todos', { status, page }],\n    fetchTodoList // This is the same as `fetchTodoList({ status, page })`\n  )\n}\n```\n\nWhenever a query's key changes, the query will automatically update:\n\n```js\nfunction Todos() {\n  const [page, setPage] = useState(0)\n\n  const { data, isLoading, error } = useQuery(\n    ['todos', { page }],\n    fetchTodoList\n  )\n\n  const onNextPage = () => {\n    setPage(page => page + 1)\n  }\n\n  return (\n    <>\n      {/* ... */}\n      <button onClick={onNextPage}>Load next page</button>\n    </>\n  )\n}\n```\n\n### Dependent Queries\n\nReact Query makes it easy to make queries that depends on other queries for both:\n\n- Parallel Queries (avoiding waterfalls) and\n- Serial Queries (when a piece of data is required for the next query to happen.\n\nTo do this effectively, you can use the following 2 approaches:\n\n#### Pass a falsey query key\n\nIf a query isn't ready to be requested yet, just pass a falsey value as the query key:\n\n```js\nconst { data: user } = useQuery(['user', { userId }])\nconst { data: projects } = useQuery(user && ['projects', { userId: user.id }]) // User is `null`, so the query key will be falsey\n```\n\n#### Use a query key function\n\nIf a function is passed, the query will not execute until the function can be called without throwing:\n\n```js\nconst { data: user } = useQuery(['user', { userId }])\nconst { data: projects } = useQuery(() => ['projects', { userId: user.id }]) // This will throw until `user` is available\n```\n\n#### Mix them together!\n\n```js\nconst [ready, setReady] = React.useState(false)\nconst { data: user } = useQuery(ready && ['user', { userId }]) // Wait for ready\nconst { data: projects } = useQuery(\n  () => ready && ['projects', { userId: user.id }] // Wait for ready and user.id\n```\n\n### Caching & Invalidation\n\nReact Query caching is automatic and uses optimistic updates and short-term caching across similar queries to always ensure a query's data is only stored once, quickly available and kept up to date with the server.\n\nAt a glance:\n\n- Caching is automatic dand aggressive by default.\n- The cache is keyed on unique `query + variables` combinations.\n- You can configure the `cacheTime` option that determines how long cache data is considered fresh before it is marked as stale\n- You can configure the `inactiveCacheTime` option that determines how long unused stale cache data is kept around before it is garbage collected\n- Stale queries are optimistically and automatically updated when new instances of that query mount or variables change\n- If stale or unused cache data that has not been garbage collected is available, it will be used as a cold-start cache for queries while they are updated.\n- Data is not normalized or stored outside of the context of its usage.\n- Caching can be turned off either globally or individually for each query\n\n> **Did You Know?** - Because React Query doesn't use document normalization in its cache (made popular with libraries like Apollo and Redux-Query), it eliminates a whole range of common issues with caching like incorrect data merges, failed cache reads/writes, and imperative maintenance of the cache.\n\n<details>\n <summary>A more detailed example of the caching lifecycle</summary>\n\n- A new usage of `useQuery(fetchTodoList, { page: 1 })` mounts\n  - Since no other queries have been made with this query + variable combination, this query will show a hard loading state and make a network request to fetch the data.\n  - It will then cache the data using `fetchTodoList` and `{ page: 1 }` as the unique identifiers for that cache.\n  - A cache expiration is scheduled for later using the `cacheTime` option as a delay (defaults to `10 * 1000` milliseconds or `10` seconds).\n- A second instance of `useQuery(fetchTodoList, { page: 1 })` mounts elsewhere\n  - Because this exact data exist in the cache from the first instance of this query, that data is immediately returned from the cache\n- `10` seconds pass since the data came in for the first instance of this query\n  - The data for these queries is marked as outdated\n- A third instance of `useQuery(fetchTodoList, { page: 1 })` mounts elsewhere\n  - Because this exact data exist in the cache from the first and second instances of this query, that data is immediately returned from the cache\n  - However, since the data has been marked as outdated, a background request is made to updated the stale data\n  - Both this instance and the other first and second instances of this query get optimistically updated with the new data from the background request\n  - A new cache expiration is scheduled for later using the `cacheTime` option as a delay.\n- All 3 instances of the `useQuery(fetchTodoList, { page: 1 })` query unmount.\n  - Since there are no more active instances to this query combination, a fallback timeout is set using `inactiveCacheTime` to garbage collect the cache (defaults to `10 * 1000` milliseconds or `10` seconds).\n  - If there is an active cache expiration scheduled already, it will be used instead.\n- No more instances of `useQuery(fetchTodoList, { page: 1 })` appear within the timeout\n  - The cache for the this query is deleted and garbage collected.\n\n</details>\n\n### Pagination\n\nIf all you need is page-based pagination, where the previous set of data is replaced with a new one, this section is not applicable to your use-case. For that, you can increment the page variable and pass it to your query via variables.\n\nHowever, if your app needs to add more data to the list along with existing one (for example, infinite loading), React Query provides you with a way to fetch additional data without deleting the current data. Let's use page-based pagination for simplicity, but assume that we want to append new todo items at the end of the list.\n\n```js\nfunction Todos() {\n  const { data, isLoading, error, refetch, isFetching } = useQuery(\n    ['todos', { page: 1 }],\n    fetchTodoList\n  )\n\n  const onFetchMore = () => {\n    refetch({\n      variables: { page: data.pagination.nextPage },\n      merge: (prev, next) => ({\n        ...next,\n        // Merge the new todos with the existing ones\n        todos: [...prev.todos, ...next.todos],\n      }),\n    })\n  }\n\n  return isLoading ? (\n    <span>Loading...</span>\n  ) : error ? (\n    <span>Error: {error.message}</span>\n  ) : data ? (\n    <>\n      <ul>\n        {data.todos.map(todo => (\n          <li key={todo.id}>{todo.title}</li>\n        ))}\n      </ul>\n      {data.pagination.hasMore && (\n        <button disabled={isFetching} onClick={onFetchMore}>\n          {isFetching ? 'Loading more todos...' : 'Load more todos'}\n        </button>\n      )}\n    </>\n  ) : null\n}\n```\n\nTo prevent you from managing the loading state of `refetch` manually (since `isLoading` will remain false when `refetch` is called), React Query exposes an `isFetching` variable. It's the same as `isLoading`, but only reflects the state of the actual fetch operation for the query.\n\n### Manual Querying\n\nIf you ever want to disable a query from automatically running, you can use the `manual = true` option. When `manual` is set to true:\n\n- The query will not automatically refetch due to changes to their query function or variables.\n- The query will not automatically refetch due to `refetchQueries` options in other queries or via `useRefetchQuery` calls.\n\n```js\nfunction Todos() {\n  const { data, isLoading, error, refetch, isFetching } = useQuery(\n    'todos',\n    fetchTodoList,\n    {\n      manual: true,\n    }\n  )\n\n  return (\n    <>\n      <button onClick={() => refetch()}>Fetch Todos</button>\n\n      {isLoading ? (\n        <span>Loading...</span>\n      ) : error ? (\n        <span>Error: {error.message}</span>\n      ) : data ? (\n        <>\n          <ul>\n            {data.map(todo => (\n              <li key={todo.id}>{todo.title}</li>\n            ))}\n          </ul>\n        </>\n      ) : null}\n    </>\n  )\n}\n```\n\n> Pro Tip: Don't use `manual` for dependent queries. Use [Dependent Queries](#dependent-queries) instead!\n\n### Retries\n\nWhen a `useQuery` query fails (the function throws an error), React Query will automatically retry the query if that query's request has not reached the max number of consecutive retries (defaults to `3`).\n\nYou can configure retries both on a global level and an individual query level.\n\n- Setting `retry = false` will disable retries\n- Setting `retry = 6` will retry failing requests 6 times before showing the final error thrown by the function\n- Setting `retry = true` will infinitely retry failing requests.\n\n```js\n// Turn off retries for all queries\nconst config = {\n  retry: false,\n}\n\nfunction App() {\n  return (\n    <ReactQueryProvider config={config}>\n      <Stuff />\n    </ReactQueryProvider>\n  )\n}\n\n// Make specific query retry a certain number of times\nconst { data, isLoading, error } = useQuery(['todos', { page: 1 }, fetchTodoList, {\n  retry: 10, // Will retry failed requests 10 times before displaying an error\n})\n```\n\n### Retry Delay with `retryDelay`\n\nBy default, retries in React Query do not happen immediately after a request fails. As is standard, a back-off delay is gradually applied to each retry attempt.\n\nThe default `retryDelay` is set to double (starting at `1000`ms) with each attempt, but not exceed 30 seconds:\n\n```js\n// Configure for all queries\nconst config = {\n  retryDelay: attemptIndex => Math.min(1000 * 2 ** attemptIndex, 30000),\n}\n\nfunction App() {\n  return (\n    <ReactQueryProvider config={config}>\n      <Stuff />\n    </ReactQueryProvider>\n  )\n}\n```\n\nThough it is not recommended, you can obviously override the `retryDelay` function/integer in both the Provider and individual query options. If set to an integer instead of a function the delay will always be the same amount of time:\n\n```js\nconst { data, isLoading, error } = useQuery('todos', fetchTodoList, {\n  retryDelay: 10000, // Will always wait 1000ms to retry, regardless of how many retries\n})\n```\n\n## Mutations\n\nUnlike queries, mutations are typically used to create/update/delete data or perform server side-effects. For this purpose, React Query exports a `useMutation` hook.\n\n### Basic Mutations\n\nAssuming the server implements a ping mutation, that returns \"pong\" string, here's an example of the most basic mutation:\n\n```js\nconst PingPong = () => {\n  const [mutate, { data, isLoading, error }] = useMutation(pingMutation)\n\n  const onPing = async () => {\n    try {\n      const data = await mutate()\n      console.log(data)\n      // { ping: 'pong' }\n    } catch {\n      // Uh oh, something went wrong\n    }\n  }\n  return <button onClick={onPing}>Ping</button>\n}\n```\n\nMutations without variables are not that useful, so let's add some variables to closer match reality.\n\n### Mutation Variables\n\nTo pass `variables` to your `mutate` function, call `mutate` with an object.\n\n```js\nconst CreateTodo = () => {\n  const [title, setTitle] = useState('')\n  const [mutate] = useMutation(createTodo)\n\n  const onCreateTodo = async e => {\n    // Prevent the form from refreshing the page\n    e.preventDefault()\n\n    try {\n      await mutate({ title })\n      // Todo was successfully created\n    } catch (error) {\n      // Uh oh, something went wrong\n    }\n  }\n\n  return (\n    <form onSubmit={onCreateTodo}>\n      <input\n        type=\"text\"\n        value={title}\n        onChange={e => setTitle(e.target.value)}\n      />\n      <br />\n      <button type=\"submit\">Create Todo</button>\n    </form>\n  )\n}\n```\n\nEven with just variables, mutations aren't all that special, but when used with the `refetchQueries` and `mutateQuery` options, they become a very powerful tool.\n\n### Invalidate and Refetch Queries from Mutations\n\nWhen a mutation succeeds, it's likely that other queries in your application need to update. Where other libraries that use normalized caches would attempt to update locale queries with the new data imperatively, React Query avoids the pitfalls that come with normalized caches and prescribes **atomic updates** instead of partial cache manipulation.\n\nFor example, assume we have a mutation to post a new todo:\n\n```js\nconst [mutate] = useMutation(postTodo)\n```\n\nWhen a successful `postTodo` mutation happens, we likely want all `todos` queries to get refetched to show the new todo item. To do this, you can use the `refetchQueries` option when calling a mutation's `mutate` function.\n\n```js\n// When this mutation succeeds, any queries with the `todos` or `reminders` query key will be refetched\nmutate(newTodo, { refetchQueries: ['todos', 'reminders'], })\n\n// The 3 queries below will be refetched when the mutation above succeeds\nconst todoListQuery = useQuery('todos', fetchTodoList)\nconst todoListQuery = useQuery(['todos', { page: 1 }, fetchTodoList)\nconst remindersQuery = useQuery('reminders', fetchReminders)\n```\n\nYou can even refetch queries with specific variables by passing a query key tuple to `refetchQueries`:\n\n```js\nmutate(newTodo, { refetchQueries: [['todos', { status: 'done' }]] })\n\n// The query below will be refetched when the mutation above succeeds\nconst todoListQuery = useQuery(['todos', { status: 'done' }], fetchTodoList)\n// However, the following query below will NOT be refetched\nconst todoListQuery = useQuery('todos', fetchTodoList)\n```\n\nIf you want to **only** refetch `todos` queries that don't have variables, you can pass a tuple with `variables` set to `false`:\n\n```js\nmutate(newTodo, { refetchQueries: [['todos', false]] })\n\n// The query below will be refetched when the mutation above succeeds\nconst todoListQuery = useQuery(['todos'], fetchTodoList)\n// However, the following query below will NOT be refetched\nconst todoListQuery = useQuery(['todos', { status: 'done' }], fetchTodoList)\n```\n\nIf you prefer that the promise returned from `mutate()` only resolves **after** any `refetchQueries` have been refetched, you can pass the `waitForRefetchQueries = true` option to `mutate`:\n\n```js\nconst [mutate] = useMutation(addTodo, {})\n\nconst run = async () => {\n  try {\n    await mutate(todo, { waitForRefetchQueries: true })\n    console.log('I will only log after all refetchQueries are done refetching!')\n  } catch {}\n}\n```\n\n### Query Updates from Mutations\n\nWhen dealing with mutations that **update** objects on the server, it's common for the new object to be automatically returned in the response of the mutation. Instead of invalidating any queries for that item and wasting a network call to refetch them again, we can take advantage of the object returned by the mutation function and update any query responses with that data that match that query using the `mutateQuery` option:\n\n```js\nconst [mutate] = useMutation(editTodo)\n\nmutate(\n  {\n    id: 5,\n    name: 'Do the laundry',\n  },\n  {\n    mutateQuery: [['todo', { id: 5 }]],\n  }\n)\n\n// The query below will be updated with the response from the mutation above when it succeeds\nconst { data, isLoading, error } = useQuery(['todo', { id: 5 }], fetchTodoByID)\n```\n\n### Manually or Optimistically Mutating Query Data\n\nIn rare circumstances, you may want to manually update a query's response outside of a mutation. To do this, you can use the exported `mutateQuery` function:\n\n```js\nimport { mutateQuery } from 'react-query'\n\n// Full replacement\nmutateQuery(['todo', { id: 5 }], newTodo)\n\n// or functional update\nmutateQuery(['todo', { id: 5 }], previous => ({ ...previous, status: 'done' }))\n```\n\n**Most importantly**, when manually mutating a query response, it naturally becomes out-of-sync with it's original source. To ease this issue, `mutateQuery` automatically triggers a background refresh of the query after it's called to ensure it stays in sync with the original source.\n\nShould choose _not_ to refetch the query, you can set the `shouldRefetch` option to `false`:\n\n```js\nimport { mutateQuery } from 'react-query'\n\n// Mutate, but do not automatically refetch the query in the background\nmutateQuery(['todo', { id: 5 }], newTodo, {\n  shouldRefetch: false,\n})\n```\n\n### Displaying Background Fetching Loading States\n\nA query's `isLoading` boolean is usually sufficient to show the initial hard-loading state for a query, but sometimes you may want to display a more subtle indicator that a query is refetching in the background. To do this, queries also supply you with an `isFetching` boolean that you can use to show that it's in a fetching state:\n\n```js\nfunction Todos() {\n  const { data: todos, isLoading, isFetching } = useQuery('todos', fetchTodos)\n\n  return isLoading ? (\n    <span>Loading...</span>\n  ) : todos ? (\n    <>\n      {isFetching ? <div>Refreshing...</div> : null}\n\n      <div>\n        {todos.map(todo => (\n          <Todo todo={todo} />\n        ))}\n      </div>\n    </>\n  ) : null\n}\n```\n\n### Displaying Global Background Fetching Loading State\n\nIn addition to individual query loading states, if you would like to show a global loading indicator when **any** queries are fetching (including in the background), you can use the `useIsFetching` hook:\n\n```js\nimport { useIsFetching } from 'react-query'\n\nfunction GlobalLoadingIndicator() {\n  const isFetching = useIsFetching()\n\n  return isFetching ? (\n    <div>Queries are fetching in the background...</div>\n  ) : null\n}\n```\n\n### Window-Focus Refetching\n\nIf a user leaves your application and returns to stale data, you may want to trigger an update in the background to update any stale queries. Thankfully, **React Query does this automatically for you**, but if you choose to disable it, you can use the `ReactQueryProvider`'s `refetchAllOnWindowFocus` option to disable it:\n\n```js\n<ReactQueryProvider config={{ refetchAllOnWindowFocus: false }}>\n  ...\n</ReactQueryProvider>\n```\n\n# API\n\n## `ReactQueryProvider`\n\n`ReactQueryProvider` is required and can optionally define defaults for all instances of `useQuery` and `useMutate` through your app:\n\n```js\n<ReactQueryProvider\n  config={{ retry, retryDelay, cachetime, invalideCacheTime }}\n>\n  ...\n</ReactQueryProvider>\n```\n\n### Options\n\nPass options to `ReactQueryProvider` by pass it a `config` prop:\n\n- `retry: Boolean | Int`\n  - If `false`, failed queries will not retry by default\n  - If `true`, failed queries will retry infinitely\n  - If set to an `Int`, eg. `3`, failed queries will retry until the failed query count meets that number\n- `retryDelay: Function(retryAttempt: Int) => Int`\n  - This function receives a `retryAttempt` integer and returns the delay to apply before the next attempt in milliseconds\n  - A function like `attempt => Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000)` applies exponential backoff\n  - A function like `attempt => attempt * 1000` applies linear backoff.\n- `cacheTime: Int`\n  - The time in milliseconds that cache data remains fresh. After a successful cache update, that cache data will become stale after this duration\n- `invalidCacheTime: Int`\n  - The time in milliseconds that unused/inactive cache data remains in memory. When a query's cache becomes unused or inactive, that cache data will be garbage collected after this duration.\n\n### Example\n\n```js\nconst config = {\n  // These are the default config options for the ReactQueryProvider\n  retry: 3,\n  retryDelay: attempt =>\n    Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000),\n  cacheTime: 10 * 1000, // 10 seconds\n  invalidCacheTime: 10 * 1000, // 10 seconds\n}\n\nfunction App() {\n  return <ReactQueryProvider config={config}>...</ReactQueryProvider>\n}\n```\n\n## `useQuery`\n\n```js\nconst {\n  data,\n  error,\n  isFetching,\n  isCached,\n  failureCount,\n  isLoading,\n  refetch,\n} = useQuery(queryKey, queryFn, {\n  manual,\n  cacheTime,\n  retry,\n  retryDelay,\n})\n```\n\n### Options\n\n- `queryKey: String | [String, Variables: Object] | falsey | Function => queryKey`\n  - **Required**\n  - The query key to use for this query.\n  - If a string is passed, it will be used as the query key\n  - If a `[String, Object]` tuple is passed, they will be serialized into a stable query key. See [Query Keys](#query-keys) for more information.\n  - If a falsey value is passed, the query will be disabled and not run automatically.\n  - If a function is passed, it should resolve to any other valid query key type. If the function throws, the query will be disabled and not run automatically.\n  - The query will automatically update when this key changes (if the key is not falsey and if `manual` is not set to `true`)\n  - `Variables: Object`\n    - If a tuple with variables is passed, this object should be **serializable**.\n    - Nested arrays and objects are supported\n    - The order of object keys is sorted to be stable before being serialized into the query key\n- `queryFn: Function(variables) => Promise(data/error)`\n  - **Required**\n  - The function that the query will use to request data\n  - Optionally receives the `variables` object passed from either the query key tuple (`useQuery(['todos', variables], queryFn)`) or the refetch method's `variables` option `refetch({ variables })`\n  - Must return a promise that will either resolves data or throws an error.\n- `manual: Boolean`\n  - Set this to `true` to disable automatic refetching when the query mounts or changes query keys.\n  - To refetch the query, use the `refetch` method returned from the `useQuery` instance.\n- `cacheTime`\n  - [See `ReactQueryProvider` options...](#reactqueryprovider)\n- `retry`\n  - [See `ReactQueryProvider` options...](#reactqueryprovider)\n- `retryDelay`\n  - [See `ReactQueryProvider` options...](#reactqueryprovider)\n\n### Query Instance\n\n- `data: null | Any`\n  - Defaults to `null`\n  - The last successfully resolved data for the query.\n- `error: null | Error`\n  - The error object for the query, if an error was thrown.\n- `isLoading: Boolean`\n  - Will be `true` if the query is both fetching and does not have any cached data to display.\n- `isFetching: Boolean`\n  - Will be `true` if the query is currently fetching, including background fetching.\n- `isCached: Boolean`\n  - Will be `true` if the query's response is currently cached.\n- `failureCount: Integer`\n  - The failure count for the query.\n  - Incremented every time the query fails.\n  - Reset to `0` when the query succeeds.\n- `refetch: Function({ variables: Object, merge: Function, disableThrow: Boolean })`\n  - A function to manually refetch the query.\n  - Supports custom variables (useful for \"fetch more\" calls)\n  - Supports custom data merging (useful for \"fetch more\" calls)\n  - Set `disableThrow` to true to disable this function from throwing if an error is encountered.\n\n## `useMutation`\n\n```js\nconst [mutate, { data, isLoading, error }] = useMutation(queryKey, {\n  refetchQueries,\n  updateQuery,\n})\n```\n\n### Options\n\n- `mutationFn: Function(variables)`\n  - **Required**\n  - The query key to use for this query.\n  - If a string is passed, it will be used as the query key\n  - If a `[String, Object]` tuple is passed, they will be serialized into a stable query key. See [Query Keys](#query-keys) for more information.\n  - If a falsey value is passed, the query will be disabled and not run automatically.\n  - If a function is passed, it should resolve to any other valid query key type. If the function throws, the query will be disabled and not run automatically.\n  - The query will automatically update when this key changes (if the key is not falsey and if `manual` is not set to `true`)\n  - `Variables: Object`\n    - If a tuple with variables is passed, this object should be **serializable**.\n    - Nested arrays and objects are supported\n    - The order of object keys is sorted to be stable before being serialized into the query key\n- `manual: Boolean`\n  - Set this to `true` to disable automatic refetching when the query mounts or changes query keys.\n  - To refetch the query, use the `refetch` method returned from the `useQuery` instance.\n\n### Query Instance\n\n- `data: null | Any`\n  - Defaults to `null`\n  - The last successfully resolved data for the query.\n- `error: null | Error`\n  - The error object for the query, if an error was thrown.\n- `isLoading: Boolean`\n  - Will be `true` if the query is both fetching and does not have any cached data to display.\n- `isFetching: Boolean`\n  - Will be `true` if the query is currently fetching, including background fetching.\n- `isCached: Boolean`\n  - Will be `true` if the query's response is currently cached.\n- `failureCount: Integer`\n  - The failure count for the query.\n  - Incremented every time the query fails.\n  - Reset to `0` when the query succeeds.\n- `refetch: Function({ variables: Object, merge: Function, disableThrow: Boolean })`\n  - A function to manually refetch the query.\n  - Supports custom variables (useful for \"fetch more\" calls)\n  - Supports custom data merging (useful for \"fetch more\" calls)\n  - Set `disableThrow` to true to disable this function from throwing if an error is encountered.\n\n## `useMutation`\n\n## `mutateQuery`\n\n## `refetchQuery`\n\n## `refetchAllQueries`\n\n## `useIsFetching`\n","license":"MIT","scripts":{"test":"cross-env CI=1 react-scripts test --env=jsdom","build":"rollup -c","start":"rollup -c -w","format":"prettier {src,src/**,example/src,example/src/**}/*.{md,js,jsx,tsx} --write","prepare":"yarn build","release":"yarn publish","now-build":"yarn && cd www && yarn && yarn build","test:watch":"react-scripts test --env=jsdom","releaseNext":"yarn publish --tag next"},"_npmUser":{"name":"tannerlinsley","email":"tannerlinsley@gmail.com"},"repository":{"url":"https://github.com/tannerlinsley/react-query.git","type":"git"},"description":"Hooks for managing, caching and syncing asynchronous and remote data in React","directories":{},"maintainers":[{"name":"tannerlinsley","email":"tannerlinsley@gmail.com"}],"dependencies":{},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"react":"^16.8.6","eslint":"5.x","rollup":"^1.12.4","prettier":"^1.18.2","cross-env":"^5.1.4","react-dom":"^16.8.6","babel-core":"7.0.0-bridge.0","@svgr/rollup":"^4.3.0","babel-eslint":"9.x","@babel/preset-env":"^7.4.5","eslint-plugin-node":"^9.1.0","@babel/preset-react":"^7.0.0","eslint-plugin-react":"7.x","rollup-plugin-babel":"^4.3.2","eslint-plugin-import":"2.x","eslint-plugin-promise":"^4.1.1","eslint-config-prettier":"^4.3.0","eslint-config-standard":"^12.0.0","eslint-plugin-flowtype":"2.x","eslint-plugin-jsx-a11y":"6.x","eslint-plugin-prettier":"^3.1.0","eslint-plugin-standard":"^4.0.0","rollup-plugin-commonjs":"^10.0.0","eslint-config-react-app":"^4.0.1","eslint-plugin-react-hooks":"1.5.0","rollup-plugin-node-resolve":"^5.0.0","eslint-config-standard-react":"^7.0.2","rollup-plugin-peer-deps-external":"^2.2.0","@babel/plugin-proposal-class-properties":"^7.4.4"},"peerDependencies":{"react":"^16.6.3","prop-types":"^15.5.4"},"_npmOperationalInternal":{"tmp":"tmp/react-query_0.0.13_1572801242029_0.15568438879880242","host":"s3://npm-registry-packages"},"_id":"react-query@0.0.13","version":"0.0.13"}