You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a state variable that holds a promise. On the click of a button, that promise is replaced with a new one (all of them are fetch requests). If the initial promise fails, the Async component helpers render the error just fine. If I click the button and the new promise fails, an Unhandled Rejection is thrown.
Here's the code that illustrates the problem:
import{useState}from'react';importAsyncfrom'react-async';asyncfunctiongetRandomNumber(){constres=awaitfetch(`https://svelte.dev/tutorial/random-number`);consttext=awaitres.text();if(res.ok){returntext;}else{thrownewError(text);}}exportdefaultfunctionApp(_props){let[promise,setPromise]=useState(getRandomNumber());return(<><buttononClick={()=>setPromise(getRandomNumber())}>
generate random number
</button><Asyncpromise={promise}><Async.Pending><p>...waiting</p></Async.Pending><Async.Fulfilled>{number=><p>The number is {number}</p>}</Async.Fulfilled><Async.Rejected>{error=><pstyle={{color: 'red'}}>{error.message}</p>}</Async.Rejected></Async></>)}
This can be reproduced with a fresh React app from create-react-app and react-async installed. The fetch call has a substantial chance of failing.
Steps:
launch the app but don't press the button
refresh the page until you see the initial request come back with an error
press the button until a new request comes back with an error
observe the unhandled promise rejection
Am I doing something wrong?
The text was updated successfully, but these errors were encountered:
I have a state variable that holds a promise. On the click of a button, that promise is replaced with a new one (all of them are
fetch
requests). If the initial promise fails, theAsync
component helpers render the error just fine. If I click the button and the new promise fails, an Unhandled Rejection is thrown.Here's the code that illustrates the problem:
This can be reproduced with a fresh React app from
create-react-app
andreact-async
installed. Thefetch
call has a substantial chance of failing.Steps:
Am I doing something wrong?
The text was updated successfully, but these errors were encountered: