I am using a firebase onSnapshot method to use realtime data in react native app and wrote a separate async function to listen to the firestore as given below, I am using useEffect to call this function and I want to return the subscriber method returning from the firestore as a cleanup function. I know that I can achieve that
Tag: promise
How to use async/await to get input from user but wait till entire condition statement is read before resolving?
I created a function that prompts the user for a URL, then validates that the entered input is actually a URL. The issue is, when I call this function from my other function, I have been able to get it to wait for user input before but it doesn’t go through the entire condition statement before returning the url. How
reactJS useState hook actual value is out dated in async promises
In my react function component I send multiple server request and update a state hook value through asynchronous promises by appending server results to state most recent value, but once promise is created, value of state hook is not updated within the running promise, so if another promise updates state value, other running promises don’t get informed and as a
Promise.all() to await the return of an object property
Inside an async function i have a loop and inside this loop i need to use await to resolve a promise from another async function. It’s work fine, but eslint says to disallow await inside of loops and use Promise.all() to resolve all promises. The problem is that my promises are in an object property: How can i figure out
Multithreading with javascript promises
Just learning promises. Javascript is single threaded right? So when it uses fetch api to make http requests it all happens in one thread? How does it manage concurrency with PromisePool then? Then two then above cannot run on multiple threads right? Just in one thread? Thanks Answer Javascript is single threaded right? No. That’s a common over-simplification. JavaScript runs
Access value from Promise for HTML Element
I’m new to React and javascript and need some help. I’m using a function that returns a Promise including an interface. I want to access the variable in the Interface and apply it in <dl><dt>{//string variable}</dt></dl>. The problem is that I’m only getting a Promise object, and I need it as a string. How can I do this? This is
How can I wait until the functions finish in Reactjs?
Hi I am new to reactjs and I am trying to build button with a function doing some calculation by Reactjs. The logic is, first I will get two lists from database by two functions. After these 2 functions return results and setState, the calculate function will continue and do its job. But somehow the state is not being updated
Displaying and hiding of loader div not working synchronously as intended in Javascript
I want a loader element to show while my Sudoku solver function is running and hide upon completion. However, what happens in practice is that the loader never shows itself (or shows and hides almost instantly) even while the solver function is running. The timer for showing performance seems to be working and acting synchronously while the loader isn’t, leading
Why is this promise returning undefined?
I am trying to write a simple function like this and I have made a firebase helper like this however, league is logging out as undefined and in here is logging out second. however, I thought it would be the other way around? I thought it would “await” for this function to resolve then once it’s resolved, it would show
Unexpected unhandledRejection event for promise which rejection does get handled
Updated, I’ve now tried explaining the behavior I’m seeing, but it’d still be great to have an answer from a credible source about the unhandledRejection behavor. I’ve also started a discussion thread on Reddit. Why do I get an unhandledRejection event (for “error f1”) in the following code? That’s unexpected, because I handle both rejections in the finally section of