Skip to content

Commit 702e1be

Browse files
committed
Update name to useFormStatus
1 parent 62badab commit 702e1be

File tree

6 files changed

+33
-43
lines changed

6 files changed

+33
-43
lines changed

compiler/packages/babel-plugin-react-compiler/src/HIR/Globals.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
BuiltInArrayId,
1212
BuiltInUseActionStateId,
1313
BuiltInUseEffectHookId,
14-
BuiltInUseFormStateId,
14+
BuiltInUseFormStatusId,
1515
BuiltInUseInsertionEffectHookId,
1616
BuiltInUseLayoutEffectHookId,
1717
BuiltInUseOperatorId,
@@ -281,13 +281,13 @@ const REACT_APIS: Array<[string, BuiltInType]> = [
281281
}),
282282
],
283283
[
284-
"useFormState",
284+
"useFormStatus",
285285
addHook(DEFAULT_SHAPES, {
286286
positionalParams: [],
287287
restParam: Effect.Freeze,
288-
returnType: { kind: "Object", shapeId: BuiltInUseFormStateId },
288+
returnType: { kind: "Object", shapeId: BuiltInUseFormStatusId },
289289
calleeEffect: Effect.Read,
290-
hookKind: "useFormState",
290+
hookKind: "useFormStatus",
291291
returnValueKind: ValueKind.Frozen,
292292
returnValueReason: ValueReason.State,
293293
}),

compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,13 +1555,15 @@ export function isSetActionStateType(id: Identifier): boolean {
15551555
);
15561556
}
15571557

1558-
export function isUseFormStateType(id: Identifier): boolean {
1559-
return id.type.kind === "Object" && id.type.shapeId === "BuiltInUseFormState";
1558+
export function isUseFormStatusType(id: Identifier): boolean {
1559+
return (
1560+
id.type.kind === "Object" && id.type.shapeId === "BuiltInUseFormStatus"
1561+
);
15601562
}
15611563

1562-
export function isSetFormStateType(id: Identifier): boolean {
1564+
export function isSetFormStatusType(id: Identifier): boolean {
15631565
return (
1564-
id.type.kind === "Function" && id.type.shapeId === "BuiltInSetFormState"
1566+
id.type.kind === "Function" && id.type.shapeId === "BuiltInSetFormStatus"
15651567
);
15661568
}
15671569

@@ -1577,7 +1579,7 @@ export function isStableType(id: Identifier): boolean {
15771579
return (
15781580
isSetStateType(id) ||
15791581
isSetActionStateType(id) ||
1580-
isSetFormStateType(id) ||
1582+
isSetFormStatusType(id) ||
15811583
isDispatcherType(id)
15821584
);
15831585
}

compiler/packages/babel-plugin-react-compiler/src/HIR/ObjectShape.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export type HookKind =
119119
| "useContext"
120120
| "useState"
121121
| "useActionState"
122-
| "useFormState"
122+
| "useFormStatus"
123123
| "useReducer"
124124
| "useRef"
125125
| "useEffect"
@@ -199,8 +199,8 @@ export const BuiltInUseStateId = "BuiltInUseState";
199199
export const BuiltInSetStateId = "BuiltInSetState";
200200
export const BuiltInUseActionStateId = "BuiltInUseActionState";
201201
export const BuiltInSetActionStateId = "BuiltInSetActionState";
202-
export const BuiltInUseFormStateId = "BuiltInUseFormState";
203-
export const BuiltInSetFormStateId = "BuiltInSetFormState";
202+
export const BuiltInUseFormStatusId = "BuiltInUseFormStatus";
203+
export const BuiltInSetFormStatusId = "BuiltInSetFormStatus";
204204
export const BuiltInUseRefId = "BuiltInUseRefId";
205205
export const BuiltInRefValueId = "BuiltInRefValue";
206206
export const BuiltInMixedReadonlyId = "BuiltInMixedReadonly";
@@ -421,7 +421,7 @@ addObject(BUILTIN_SHAPES, BuiltInUseActionStateId, [
421421
],
422422
]);
423423

424-
addObject(BUILTIN_SHAPES, BuiltInUseFormStateId, [
424+
addObject(BUILTIN_SHAPES, BuiltInUseFormStatusId, [
425425
["0", { kind: "Poly" }],
426426
[
427427
"1",
@@ -435,7 +435,7 @@ addObject(BUILTIN_SHAPES, BuiltInUseFormStateId, [
435435
calleeEffect: Effect.Read,
436436
returnValueKind: ValueKind.Primitive,
437437
},
438-
BuiltInSetFormStateId
438+
BuiltInSetFormStatusId
439439
),
440440
],
441441
]);

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useActionState-dispatch-considered-as-non-reactive.expect.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,20 @@ import { c as _c } from "react/compiler-runtime";
2828
import { useActionState } from "react";
2929

3030
function Component() {
31-
const $ = _c(2);
31+
const $ = _c(1);
3232
const [actionState, dispatchAction] = useActionState();
3333
let t0;
3434
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
35-
t0 = () => {
35+
const onSubmitAction = () => {
3636
dispatchAction();
3737
};
38+
39+
t0 = <Foo onSubmitAction={onSubmitAction} />;
3840
$[0] = t0;
3941
} else {
4042
t0 = $[0];
4143
}
42-
const onSubmitAction = t0;
43-
let t1;
44-
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
45-
t1 = <Foo onSubmitAction={onSubmitAction} />;
46-
$[1] = t1;
47-
} else {
48-
t1 = $[1];
49-
}
50-
return t1;
44+
return t0;
5145
}
5246

5347
function Foo() {}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useFormState-dispatch-considered-as-non-reactive.expect.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
## Input
33

44
```javascript
5-
import { useFormState } from "react-dom";
5+
import { useFormStatus } from "react-dom";
66

77
function Component() {
8-
const [formState, dispatchForm] = useFormState();
8+
const [formState, dispatchForm] = useFormStatus();
99
const onSubmitForm = () => {
1010
dispatchForm();
1111
};
@@ -25,29 +25,23 @@ export const FIXTURE_ENTRYPOINT = {
2525

2626
```javascript
2727
import { c as _c } from "react/compiler-runtime";
28-
import { useFormState } from "react-dom";
28+
import { useFormStatus } from "react-dom";
2929

3030
function Component() {
31-
const $ = _c(2);
32-
const [formState, dispatchForm] = useFormState();
31+
const $ = _c(1);
32+
const [formState, dispatchForm] = useFormStatus();
3333
let t0;
3434
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
35-
t0 = () => {
35+
const onSubmitForm = () => {
3636
dispatchForm();
3737
};
38+
39+
t0 = <Foo onSubmitForm={onSubmitForm} />;
3840
$[0] = t0;
3941
} else {
4042
t0 = $[0];
4143
}
42-
const onSubmitForm = t0;
43-
let t1;
44-
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
45-
t1 = <Foo onSubmitForm={onSubmitForm} />;
46-
$[1] = t1;
47-
} else {
48-
t1 = $[1];
49-
}
50-
return t1;
44+
return t0;
5145
}
5246

5347
function Foo() {}
@@ -60,4 +54,4 @@ export const FIXTURE_ENTRYPOINT = {
6054
```
6155
6256
### Eval output
63-
(kind: ok)
57+
(kind: exception) object is not iterable (cannot read property Symbol(Symbol.iterator))

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useFormState-dispatch-considered-as-non-reactive.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { useFormState } from "react-dom";
1+
import { useFormStatus } from "react-dom";
22

33
function Component() {
4-
const [formState, dispatchForm] = useFormState();
4+
const [formState, dispatchForm] = useFormStatus();
55
const onSubmitForm = () => {
66
dispatchForm();
77
};

0 commit comments

Comments
 (0)