`promise` is undefined until first load/run
See original GitHub issueIn 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:
- Created 4 years ago
- Comments:20 (16 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@bogdansoare I feel your pain. I’m actually inclined to restore the chainability of
runby returning a Thenable (PromiseLike) from it. Because it’s not an actual Promise it avoids theuncaught exceptionissue (althoughawaitwill 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 thepromiseprop is causing more harm than good.also having this issue,
runshould return a promise