question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useAsyncTaskFetch: pending is "true" from the start

See original GitHub issue

Hi, noticed some weird behaviour when firing useAsyncTaskFetch by using the .start() method.

Pending status is set to true when fetch is not started, and also .started is not set to false after fetch is complete.

Here’s demo: https://codesandbox.io/s/react-hooks-async-demo-ebe5n You can see loading state from the start, and button is disabled after fetch is done.

Also, maybe it’s codesandbox related, but after installing “react-hooks-async” dependency, there was an error

Could not find dependency: ‘core-js’ relative to ‘/node_modules/react-hooks-async/dist/index.js’

so i had to add it manually.

ADDED 30.08.19 Found one more thing. If you remove disabled attribute of the button in that codesanbox demo, and fire another fetch while previous is running (better do it in slow3g mode), the request is canceled and another one is started, that’s ok, but the task has pending status false . I looked into use-async-task.js and it looks like after firing next request, forceUpdateRef.current(func); of the previous task object runs after forceUpdateRef.current(func); of the next task. So we get pending state of the finished task. As a workaround i added this to the task object:

safeStart: () => {
      task.abort();
      setTimeout(() => {
        task.start();
      }, 0);

and exporting it as a start method

  return useMemo(
    () => ({
      start: task.safeStart,

and it worked ok, JFYI

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
bugleevcommented, Sep 1, 2019

Thank you for your work! Tools you are creating are so good!

0reactions
dai-shicommented, Sep 1, 2019

Published: https://www.npmjs.com/package/react-hooks-async/v/3.4.0

I will close this issue. But we still look for better solutions. Any new ideas/suggestions are welcome (it would probably be better to file a new issue).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android : Get status of Asynctask and wait - Stack Overflow
I am using Asynctask to load all the contacts from the device. Although it has been discussed many times that Contacts.Contract is really...
Read more >
AsyncTask.Status - Android Developers
On this page; Summary. Enum values; Public methods; Inherited methods. Enum values. FINISHED; PENDING; RUNNING. Public methods. valueOf; values.
Read more >
Returning Task<bool> that involves a pending Task
I never went beyond returning Task.FromResult(computedValue) in my asynchronous programming. I was wondering if it is possible to return a ...
Read more >
Coroutines and Tasks — Python 3.11.1 documentation
Wrap the coro coroutine into a Task and schedule its execution. Return the Task object. ; If name is not None , it...
Read more >
Async Await JavaScript Tutorial – How to Wait for a Function to ...
This means that when code is executed, JavaScript starts at the top ... ever wondered why you can use fetch in JavaScript when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found