mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Repro for destructure declaration of context variable
We don't have a `DestructureContext` equivalent of `StoreContext`, so variables that are declared via destructuring and later reassigned trigger the invariant that all mentions of a variable must be consistently local or context. The next PR adds a todo for this case.
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import { Stringify } from "shared-runtime";
|
||||
|
||||
function Component({ foo }) {
|
||||
let bar = foo.bar;
|
||||
return (
|
||||
<Stringify
|
||||
handler={() => {
|
||||
foo = true;
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
2 |
|
||||
3 | function Component({ foo }) {
|
||||
> 4 | let bar = foo.bar;
|
||||
| ^^^ [ReactForget] Invariant: Expected all references to a variable to be consistently local or context references. Identifier <unknown> foo$1 is referenced as a context variable, but was previously referenced as a local variable (4:4)
|
||||
5 | return (
|
||||
6 | <Stringify
|
||||
7 | handler={() => {
|
||||
```
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import { Stringify } from "shared-runtime";
|
||||
|
||||
function Component({ foo }) {
|
||||
let bar = foo.bar;
|
||||
return (
|
||||
<Stringify
|
||||
handler={() => {
|
||||
foo = true;
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user