mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[hir] Add invariant to check if useMemo callback accepts args
This commit is contained in:
@@ -100,6 +100,14 @@ export function inlineUseMemo(fn: HIRFunction): void {
|
||||
lambda.loc
|
||||
);
|
||||
}
|
||||
|
||||
if (body.loweredFunc.params.length > 0) {
|
||||
CompilerError.invariant(
|
||||
"Did not expect any arguments to useMemo callback",
|
||||
body.loc
|
||||
);
|
||||
}
|
||||
|
||||
// We know this function is used for useMemo and can prune it later
|
||||
useMemoFunctions.add(lambda.identifier.id);
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @inlineUseMemo
|
||||
function component(a, b) {
|
||||
let x = useMemo((c) => a, []);
|
||||
return x;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
[ReactForget] Invariant: Did not expect any arguments to useMemo callback (3:3)
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// @inlineUseMemo
|
||||
function component(a, b) {
|
||||
let x = useMemo((c) => a, []);
|
||||
return x;
|
||||
}
|
||||
Reference in New Issue
Block a user