- New check to stop runaway effects. If you use
useAsyncData
hook unproperly, causing an infinite lop, now you will get an error explaining what happened and how to address it.
render
method has been moved to anAsync
class method.render(someAsync, { ... }
becomessomeAsync.render({ ... })
- Now all
Async
classes use the genericPayload
param:
export type Async<Payload> =
| InitAsync<Payload>
| InProgressAsync<Payload>
| SuccessAsync<Payload>
| ErrorAsync<Payload>;
- Updated dependencies.
- Migrated from
npm
toyarn
- Fixed clean up on
useAsyncTask
anduseManyAsyncTasks
.
- Fixed typing for
getPayload
, and added tests for it.
- Minimal updates to README.
- New
useManyAsyncTasks
hook. It works exactly the same wayuseAsyncTask
does, but this hook can be used to track multiple async tasks of the same type. Instead of returning anAsyncTask
, it returns anAsyncTask
getter. Use any key as input to obtain the associatedAsyncTask
.
useAsyncTask
tasks don't get aborted when triggered multiple times or on component unmounting, only via the providedabort
function. State updates still get cancelled on component unmounting.useAsyncData
anduseAsyncTask
now return an object (anAsyncData
or anAsyncTask
) instead of a tuple. These objects are anAsync
including extra methods, likerefresh
,trigger
orabort
.- Many helper methods have been moved to class methods or constructors.
newInit(aborted)
becomesnew InitAsync(aborted)
...isInit(someAsync)
becomessomeAsync.isInit()
...getPayload(someAsync)
becomessomeAsync.getPayload()
.getError(someAsync)
becomessomeAsync.getError()
.
- Updated and extended README.
- Fixed outdated intro in README.
This version is a major API update, to better match how the library is used. Main change: we have split useAsyncTask
hook in 2: useAsyncData
for data fetching use cases and useAsyncTask
for data mutation use cases. See the docs on README.md to better understand them.
- New
useAsyncData
hook. Similar to previous hook, with subtle differences. It runs agetData
async task as an effect by default. I can be re-triggered and reset manually, and it provides adisable
option to keep the effect —and manual triggers— inactive.
useAsyncTask
is different to previous version. I receives agetTask
function that provides theAbortSignal
and returns a function with any args that will be the async task. It is never run as an effect. You can only trigger it manually with the returned "trigger" function, and you can provide any args to the task via the trigger function args (they are forwarded).task
helper method renamed totriggerTask
.
- Updated README parts related to hooks. Minors everywhere in README too.
- Migrated tests to Typescript.
- The
AbortSignal
thatuseAsyncTask
provides as input parameter of the input function, is now optional. This is because its availability depends on browser compatibility.
- Fixed broken IE compatibility because of
AbortController
. - Fixed undesired transition from
SuccessAsync
toInProgressAsync
when the task fromuseAsyncTask
is triggered as an effect. Now it transitions to an invalidatedSuccessAsync
.
- Updated
useAsyncTask
in API Reference in README.
- Fixed bug in
AsyncViewContainer
return type, preventing Typescript compilation.
- Added
useAsyncTask
to API Reference in README.
- Typescript source files included in package bundle to enable "Go to Definition" inspection.
- README minimal updates. Added the turtle! 🐢
- CHANGELOG style enhanced.
- Added more tests to
render
function. - Dropped source maps in package bundle.
- README badges updated.
- Added Travis CI and coveralls coverage report.
This is a relevant new verion. We have reached a more stable version of useAsyncTask
hook: it finally meets exhaustive-deps
rule, avoiding some bugs and making its API more intuitive. There are also new features regarding aborting tasks and race conditions. We have also added tests.
useAsyncTask
handles race condition prevention.useAsyncTask
provides anAbortSignal
at the input function to make it abortable.- Added
aborted
substate toInitAsync
. Adapted helper methods,render
anduseAsyncTask
accordingly.
- Updated
useAsyncTask
:- New boolean
triggerAsEffect
option instead ofautoTriggerWith
to trigger the async task automatcally. - Removed
onChange
option.
- New boolean
- Fixed
errorRender
not being rendered atAsyncViewContainer
in some cases. - Fixed
AsyncViewContainer
properly acceptingnull
as render props.
- README updated.
- Added tests.
- Prevented racing conditions in
useAsyncData
when triggering an Async task times. - Prevented undesired state updates from
useAsyncData
when reseting anInProgress
Async.
- Renamed
useAsyncData
touseAsyncTask
- The
trigger
function returned byuseAsyncData
and the helper methodtask
now return a promise of the resultingAsync
instead ofvoid
.
- Deleted
useAsyncData
broken infinite loops detection in auto-trigger effect. We might add a new one in the future.
- README updated.
Big refactor for the sake of simplicity and understandability. Significantly revamped README.md to to explain the library more clearly.
useAsyncData
now detects, prevents and logs (console.error
) infinite loops caused by inappropriate dependencies for the auto-trigger effect.
useAsyncData
: always returns new trigger and reset functions. Dependencies in 3rd arg only affect the auto-trigger effect now.AsyncViewContainer
: renamed most props to be more consistent and descriptive.render
: args 2 to 5 (render functions) have become just one single arg: an object with one optional property per render function.- Helper functions:
- Now exported directly at top level, instead of under the
async
object. - Renamed many of them, and merged some of them into one.
- Now exported directly at top level, instead of under the
- README updated.
useAsyncData
hook now accepts a 3rd parameter as dependencies for the hook, overriding the first 2 parameters as dependencies.AsyncViewContainer
render props acceptnull
to render nothing.
- README updated.
useAsyncData
hook now includes all inputs as dependencies. Be specially careful if you useautoTriggerWith
, since it might triggergetData
on every render.
render
acceptsnull
as parameter to render nothing at the corresponding async state render.
- README updated.
Not documented: too early stages.