alexlafroscia / use-task

A React hook for running and cancelling asynchronous tasks
https://use-task.now.sh
24 stars 1 forks source link

refactor: move task state to `current` property #17

Closed alexlafroscia closed 5 years ago

alexlafroscia commented 5 years ago

Inspired by React Refs and how they can be used to model mutable state within React, I have decided that it might be easier to organize the current state of a task in the same way, as it too can change over time.

This change allows a TaskInstance to be returned immediately after performing it, but still allows for handling a change in state the same way that one would handle any other change to a Ref.

Now, properties about the state of a task will be accessed off of TaskInstance.current.

The .lastSuccessful property was updated to be an instance of TaskState, since once a task has completed, the ability to await the result or cancel the task is irrelevant.

vercel[bot] commented 5 years ago

This pull request is automatically deployed with Now. To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://use-task-git-use-ref.alexlafroscia.now.sh