dillon1000/react

Commit

`act`: Resolve to return value of scope function (#21759)

When migrating some internal tests I found it annoying that I couldn't
return anything from the `act` scope. You would have to declare the
variable on the outside then assign to it. But this doesn't play well
with type systems — when you use the variable, you have to check
the type.

Before:

```js
let renderer;
act(() => {
  renderer = ReactTestRenderer.create(<App />);
})

// Type system can't tell that renderer is never undefined
renderer?.root.findByType(Component);
```

After:

```js
const renderer = await act(() => {
  return ReactTestRenderer.create(<App />);
})
renderer.root.findByType(Component);
```
Browse files
Changed paths3 files
First-parent comparison
M packages/react-reconciler/src/__tests__/ReactIsomorphicAct-test.js ModifiedM packages/react-test-renderer/src/ReactTestRenderer.js ModifiedM packages/react/src/ReactAct.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…