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.

`promise` is undefined until first load/run

See original GitHub issue

In Version 8 the run method no longer returns a promise. Instead the promise prop should be used. However, when using useFetch, the promise property is undefined. Here is a test that demonstrates this:

  test("defer=true allows using the promise", () => {
    let check = 0
    const component = (
      <Fetch input="/test" options={{ defer: true }}>
        {({ run, promise }) => (
          <button
            onClick={() => {
              run()
              promise
                .then(() => {
                  return (check = 1)
                })
                .catch(() => {})
            }}
          >
            run
          </button>
        )}
      </Fetch>
    )
    const { getByText } = render(component)
    fireEvent.click(getByText("run"))
    expect(check).toEqual(1)
  })

I’ll also add a Pull-Request with these failing tests.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (16 by maintainers)

github_iconTop GitHub Comments

6reactions
ghengeveldcommented, Aug 30, 2019

@bogdansoare I feel your pain. I’m actually inclined to restore the chainability of run by returning a Thenable (PromiseLike) from it. Because it’s not an actual Promise it avoids the uncaught exception issue (although await will still throw on rejection because it treats the Thenable as a Promise). However I think we should be careful not to regress in previously resolved problems. It’s clear that the promise prop is causing more harm than good.

5reactions
bogdansoarecommented, Aug 30, 2019

also having this issue, run should return a promise

Read more comments on GitHub >

github_iconTop Results From Across the Web

`promise` is undefined until first load/run · Issue #92
In Version 8 the run method no longer returns a promise. Instead the promise prop should be used. However, when using useFetch, the...
Read more >
Promise is undefined - javascript
Your third approach is the good one, but you're wrong when you "resolve" the deferred just before returning the promise. You make it...
Read more >
Media Capture and Streams
This document defines a set of JavaScript APIs that allow local media, including audio and video, to be requested from a platform.
Read more >
Resolving the JavaScript Promise Error "TypeError: Cannot ...
TypeError: Cannot read property 'then' of undefined. In this guide, we will cover two code examples containing a bugs that cause this TypeError ......
Read more >
JavaScript (ES2015+) Enlightenment
First argument is resolution function, called when promise is resolved, second is a rejection function, called if the promise is rejected). Notes: The...
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