mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
[hir] Add invariant to check if useMemo callback accepts args
This commit is contained in:
1 parent
74f5e26e00
commit
fd252e42ab
3 files changed
+33
No files matched your search
@@ -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