Skip to content

Commit 274c980

Browse files
authored
Warn for useFormState on initial render (#30292)
This was missed in the mount dev dispatcher. It was only in the rerender dispatcher which means that it was only logged during the rerender. Since DevTools can hide logs during rerenders, this hid the warning in StrictMode.
1 parent 21129d3 commit 274c980

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

fixtures/flight/src/Counter.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
'use client';
22

33
import * as React from 'react';
4-
import {useFormState} from 'react-dom';
54

65
import Container from './Container.js';
76

87
export function Counter({incrementAction}) {
9-
const [count, incrementFormAction] = useFormState(incrementAction, 0);
8+
const [count, incrementFormAction] = React.useActionState(incrementAction, 0);
109
return (
1110
<Container>
1211
<form>

packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
'use strict';
1212

1313
let React;
14-
let ReactDOM;
1514
let ReactTestRenderer;
1615
let ReactDebugTools;
1716
let act;
@@ -34,7 +33,6 @@ describe('ReactHooksInspectionIntegration', () => {
3433
jest.resetModules();
3534
React = require('react');
3635
ReactTestRenderer = require('react-test-renderer');
37-
ReactDOM = require('react-dom');
3836
act = require('internal-test-utils').act;
3937
ReactDebugTools = require('react-debug-tools');
4038
useMemoCache = require('react/compiler-runtime').c;
@@ -2658,9 +2656,9 @@ describe('ReactHooksInspectionIntegration', () => {
26582656
});
26592657

26602658
// @gate enableAsyncActions
2661-
it('should support useFormState hook', async () => {
2659+
it('should support useActionState hook', async () => {
26622660
function Foo() {
2663-
const [value] = ReactDOM.useFormState(function increment(n) {
2661+
const [value] = React.useActionState(function increment(n) {
26642662
return n;
26652663
}, 0);
26662664
React.useMemo(() => 'memo', []);
@@ -2689,7 +2687,7 @@ describe('ReactHooksInspectionIntegration', () => {
26892687
},
26902688
"id": 0,
26912689
"isStateEditable": false,
2692-
"name": "FormState",
2690+
"name": "ActionState",
26932691
"subHooks": [],
26942692
"value": 0,
26952693
},

packages/react-dom/src/__tests__/ReactDOMFizzForm-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ describe('ReactDOMFizzForm', () => {
4040
act = require('internal-test-utils').act;
4141
container = document.createElement('div');
4242
document.body.appendChild(container);
43-
if (__VARIANT__) {
44-
// Remove after API is deleted.
45-
useActionState = require('react-dom').useFormState;
46-
} else {
47-
useActionState = require('react').useActionState;
48-
}
43+
// TODO: Test the old api but it warns so needs warnings to be asserted.
44+
// if (__VARIANT__) {
45+
// Remove after API is deleted.
46+
// useActionState = require('react-dom').useFormState;
47+
// }
48+
useActionState = require('react').useActionState;
4949
});
5050

5151
afterEach(() => {

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3994,6 +3994,7 @@ if (__DEV__) {
39943994
): [Awaited<S>, (P) => void, boolean] {
39953995
currentHookNameInDev = 'useFormState';
39963996
mountHookTypesDev();
3997+
warnOnUseFormStateInDev();
39973998
return mountActionState(action, initialState, permalink);
39983999
};
39994000
(HooksDispatcherOnMountInDEV: Dispatcher).useActionState =

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ describe('ReactFlightDOMForm', () => {
7373
ReactDOMClient = require('react-dom/client');
7474
act = React.act;
7575

76-
if (__VARIANT__) {
77-
// Remove after API is deleted.
78-
useActionState = require('react-dom').useFormState;
79-
} else {
80-
useActionState = require('react').useActionState;
81-
}
76+
// TODO: Test the old api but it warns so needs warnings to be asserted.
77+
// if (__VARIANT__) {
78+
// Remove after API is deleted.
79+
// useActionState = require('react-dom').useFormState;
80+
// }
81+
useActionState = require('react').useActionState;
8282
container = document.createElement('div');
8383
document.body.appendChild(container);
8484
});

0 commit comments

Comments
 (0)