Description
Do you want to request a feature or report a bug?
Feature
A couple of things have surprised me about the new asynchronous act
API.
1. Act doesn't return a promise.
Currently the act
function returns an object with a then
method that doesn't return a promise.
Recently, I tried to write something like:
act(() => {
return doSomethingAsynchronous()
})
.then(() => {
// ...
})
.then(() => {
// ...
})
The second .then
call throws an error because the value that is returned from act
isn't a full-fledged Promise
, but rather just an object that contains a .then
method that returns undefined
. This is fine for simple async
/await
cases, but definitely caught me by surprise.
2. Act discards the returned value.
Act also throws away the value returned from the async function callback, which makes it harder to use the values generated there. For example, if I wanted to use the value yielded by doSomethingAsynchronous
, I would need to introduce a mutable variable:
let returnedValue;
await act(async () => {
returnedValue = await doSomethingAsynchronous()
})
// use returnedValue here
If act
simply propogates the returned value from the asynnchronous callback, this will solve the confusing bits above, allowing for things like:
const returnedValue = await act(() => doSomethingAsynchronous())