mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Detect unknown hooks on React namespace
Handles an edge-case from earlier in the stack. When looking up a property on a shape, if the property is defined we return it. But if it isn't defined, and the property name is a hook, we treat it like a default custom hook.
This commit is contained in:
@@ -374,9 +374,12 @@ export class Environment {
|
||||
loc: null,
|
||||
suggestions: null,
|
||||
});
|
||||
return (
|
||||
shape.properties.get(property) ?? shape.properties.get("*") ?? null
|
||||
);
|
||||
let value =
|
||||
shape.properties.get(property) ?? shape.properties.get("*") ?? null;
|
||||
if (value === null && isHookName(property)) {
|
||||
value = this.#getCustomHookType();
|
||||
}
|
||||
return value;
|
||||
} else if (isHookName(property)) {
|
||||
return this.#getCustomHookType();
|
||||
} else {
|
||||
|
||||
+13
-4
@@ -27,21 +27,30 @@ import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import * as React from "react";
|
||||
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(2);
|
||||
const $ = useMemoCache(4);
|
||||
const c_0 = $[0] !== props.value;
|
||||
let t0;
|
||||
if (c_0) {
|
||||
t0 = (() => {
|
||||
t0 = () => {
|
||||
const x = [];
|
||||
x.push(props.value);
|
||||
return x;
|
||||
})();
|
||||
};
|
||||
$[0] = props.value;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const x_0 = t0;
|
||||
const c_2 = $[2] !== t0;
|
||||
let t1;
|
||||
if (c_2) {
|
||||
t1 = t0();
|
||||
$[2] = t0;
|
||||
$[3] = t1;
|
||||
} else {
|
||||
t1 = $[3];
|
||||
}
|
||||
const x_0 = t1;
|
||||
return x_0;
|
||||
}
|
||||
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component(props) {
|
||||
let x = null;
|
||||
if (props.cond) {
|
||||
x = React.useNonexistentHook();
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
[ReactForget] InvalidReact: Hooks must always be called in a consistent order, and may not be called conditionally. See the Rules of Hooks (https://react.dev/warnings/invalid-hook-call-warning) (4:4)
|
||||
```
|
||||
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
function Component(props) {
|
||||
let x = null;
|
||||
if (props.cond) {
|
||||
x = React.useNonexistentHook();
|
||||
}
|
||||
return x;
|
||||
}
|
||||
Reference in New Issue
Block a user