mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[hir] Check if callee before pruning member path
This commit is contained in:
@@ -2488,7 +2488,10 @@ function gatherCapturedDeps(
|
||||
if (path.isMemberExpression()) {
|
||||
// For CallExpression, we need to depend on the receiver, not the
|
||||
// function itself.
|
||||
if (path.parent.type === "CallExpression") {
|
||||
if (
|
||||
path.parent.type === "CallExpression" &&
|
||||
path.parent.callee === path.node
|
||||
) {
|
||||
path = path.get("object");
|
||||
}
|
||||
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Foo(props) {
|
||||
const onFoo = useCallback(
|
||||
(reason) => {
|
||||
log(props.router.location);
|
||||
},
|
||||
[props.router.location]
|
||||
);
|
||||
|
||||
return onFoo;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
function Foo(props) {
|
||||
const $ = React.unstable_useMemoCache(2);
|
||||
const c_0 = $[0] !== props.router.location;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = (reason) => {
|
||||
log(props.router.location);
|
||||
};
|
||||
$[0] = props.router.location;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const onFoo = t0;
|
||||
return onFoo;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
function Foo(props) {
|
||||
const onFoo = useCallback(
|
||||
(reason) => {
|
||||
log(props.router.location);
|
||||
},
|
||||
[props.router.location]
|
||||
);
|
||||
|
||||
return onFoo;
|
||||
}
|
||||
Reference in New Issue
Block a user