mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Repro for memoized hook within logical expression
Repro of a bug in which we incorrect memoize hook calls that are inside logical expressions (though the bug could occur for ternaries, optional calls, and sequence expressions too).
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
const user = useFragment(graphql`...`, props.user) ?? {};
|
||||
return user.name;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(2);
|
||||
const c_0 = $[0] !== props.user;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = useFragment(graphql`...`, props.user) ?? {};
|
||||
$[0] = props.user;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const user = t0;
|
||||
return user.name;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
function Component(props) {
|
||||
const user = useFragment(graphql`...`, props.user) ?? {};
|
||||
return user.name;
|
||||
}
|
||||
Reference in New Issue
Block a user