14 Commits

Author SHA1 Message Date
Victor Lopez
961229226b feat: add two more tests of the cancel method 2021-02-02 22:47:19 -06:00
Victor Lopez
c6346c0bb0 feat: return the cancelOutstandingRequest method in the index after the refetch method
The new index of the makeUseAxios hook return will allow for manual
cancellation of outstanding requests.
2021-02-02 21:39:21 -06:00
Simone Busoli
b218e689ae feat: default options 2021-01-13 22:49:44 +01:00
Simone Busoli
1349b1d404 chore: repo maintenance 2021-01-02 12:23:29 +01:00
Simone Busoli
74b19e8532 test: remove usage of deprecated wait function 2020-10-28 23:50:03 +01:00
Simone Busoli
9218707871 feat(269): options re-evaluation
Fixes #269

Options are now re-evaluated when they change, which can be used to change the behavior

of the component where the hook is used based on internal component state.

For example, the `manual` option could be initially true and then set to false based on

the value of a state property, causing the request to fire when this happens.

Similarly, the `useCache` option could be set to true (its default value) then to false

based on a condition, forcing the next request to skip the cache.

Check out [this example](https://codesandbox.io/s/axios-hooks-options-change-v23tl)
and the docs for additional information.
2020-07-04 18:29:17 +02:00
Simone Busoli
fff9ffed1f feat: store response in cache when skipping cache for request
BREAKING CHANGE:

This release introduces a fundamental change in the caching mechanism.

The main difference is that requests that don't use the cache
will store the response in the cache anyway, making the behavior
of the library more intuitive and predictable.

In other words, `{ useCache: false }` will only skip _reading_ from the cache,
but it will write the response to the cache in any case.

The docs contain a caching example providing a full overview of
how the new caching behavior works.

A potential side effect of the new behavior, which we tried mitigating,
is that the `refetch` function returned by the hook, which was always
skipping the cache previously, now stores the response in cache.
Because of this, it must generate a key for the cache, which is created
based on the configuration provided as the first argument to the `refetch`
function itself.

Because the `refetch` function is often provided directly to DOM event handlers:

```
<button onClick={refetch} />
```

this would no longer work because the first argument will be the React event and
we cannot generate a cache key from that, and it wouldn't make much sense either.
Because this is a fairly common scenario, we implemented a specific handling for
this case. If the first argument is an event, it is ignored and considered as if
no configuration override was provided.
2020-06-24 18:13:31 +02:00
Simone Busoli
0de127e304 feat(250): all axios-hooks-generated requests cancel each other
fixes #250

This will make it possible to pass the refetch function down to children component and let them
invoke it, without erroring on a missing token.

New behavior: cancelation errors are thrown for requests generated by the `refetch` function.
This is more consistent with how response and other errors are returned when fetching manually.
2020-06-21 14:37:07 +02:00
Simone Busoli
067b6d8052 test: add tests 2020-06-21 13:39:18 +02:00
Simone Busoli
b8f504a1e8 feat(199): add ability to disable cache
This feature introduces the ability to disable caching
entirely when using `configure` or `makeUseAxios`,
by setting the `cache` option to false:

```
// with configure
configure({ cache: false })

// with makeUseAxios
const useAxios = makeUseAxios({ cache: false })
```

fixes #199
2020-04-11 12:59:07 +02:00
Simone Busoli
2b0e9a58ed feat: support multiple instances of useAxios configured independently
See README for details about how to use the feature: https://github.com/simoneb/axios-hooks/#multiple-hook-instances

fix #98
2019-11-30 22:48:26 +01:00
Simone Busoli
4a63b6eab9 fix: use StaticAxios for cancellation as AxiosInstance doesn't expose it
fix #80
2019-11-13 21:12:45 +01:00
Simone Busoli
307c7c1565 fix: do not dispatch state updates when requests are cancelled
fix #74
2019-11-10 18:01:00 +01:00
Simone Busoli
5ba0187199 test: move test files to own folder 2019-11-10 16:01:10 +01:00