Skip to content

Commit

Permalink
Warn when using useFormState (#28668)
Browse files Browse the repository at this point in the history
## Overview

useFormState has been replaced with useActionState. Warn when it's used.

Also removes the `experimental_useFormState` warnings.

DiffTrain build for commit 18812b6.
  • Loading branch information
rickhanlonii committed Mar 29, 2024
1 parent d777384 commit f477752
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<2123de3808a6ddc6df79e3bd382b5c8a>>
* @generated SignedSource<<bcb9ae48fd24d391c11eab7a159bcc36>>
*/

"use strict";
Expand Down Expand Up @@ -7631,11 +7631,13 @@ if (__DEV__) {
var didWarnUncachedGetSnapshot;
var didWarnAboutUseWrappedInTryCatch;
var didWarnAboutAsyncClientComponent;
var didWarnAboutUseFormState;

{
didWarnAboutMismatchedHooksForComponent = new Set();
didWarnAboutUseWrappedInTryCatch = new Set();
didWarnAboutAsyncClientComponent = new Set();
didWarnAboutUseFormState = new Set();
} // The effect "instance" is a shared object that remains the same for the entire
// lifetime of an effect. In Rust terms, a RefCell. We use it to store the
// "destroy" function that is returned from an effect, because that is stateful.
Expand Down Expand Up @@ -7778,6 +7780,24 @@ if (__DEV__) {
}
}

function warnOnUseFormStateInDev() {
{
var componentName = getComponentNameFromFiber(
currentlyRenderingFiber$1
);

if (!didWarnAboutUseFormState.has(componentName)) {
didWarnAboutUseFormState.add(componentName);

error(
"ReactDOM.useFormState has been deprecated and replaced by " +
"React.useActionState. Please update %s to use React.useActionState.",
componentName
);
}
}
}

function warnIfAsyncClientComponent(Component) {
{
// This dev-only check only works for detecting native async functions,
Expand Down Expand Up @@ -10626,6 +10646,7 @@ if (__DEV__) {
function useFormState(action, initialState, permalink) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
warnOnUseFormStateInDev();
return mountActionState(action, initialState);
};

Expand Down Expand Up @@ -10780,6 +10801,7 @@ if (__DEV__) {
) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
warnOnUseFormStateInDev();
return updateActionState(action);
};

Expand Down Expand Up @@ -10939,6 +10961,7 @@ if (__DEV__) {
) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
warnOnUseFormStateInDev();
return rerenderActionState(action);
};

Expand Down Expand Up @@ -26249,7 +26272,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "19.0.0-canary-5cab92f5";
var ReactVersion = "19.0.0-canary-bf3f1a01";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a73c3450e1b528fa6cb3e94fa4d4359c7a4b61f1
18812b645c93a9c42f931fae57bbbab9c1f402b8
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<359ce6fb063e371084bf38d1957253bd>>
* @generated SignedSource<<dbb809a434e7b6781bf5289b294a7b12>>
*/

"use strict";
Expand Down Expand Up @@ -11435,11 +11435,13 @@ to return true:wantsResponderID| |
var didWarnUncachedGetSnapshot;
var didWarnAboutUseWrappedInTryCatch;
var didWarnAboutAsyncClientComponent;
var didWarnAboutUseFormState;

{
didWarnAboutMismatchedHooksForComponent = new Set();
didWarnAboutUseWrappedInTryCatch = new Set();
didWarnAboutAsyncClientComponent = new Set();
didWarnAboutUseFormState = new Set();
} // The effect "instance" is a shared object that remains the same for the entire
// lifetime of an effect. In Rust terms, a RefCell. We use it to store the
// "destroy" function that is returned from an effect, because that is stateful.
Expand Down Expand Up @@ -11582,6 +11584,24 @@ to return true:wantsResponderID| |
}
}

function warnOnUseFormStateInDev() {
{
var componentName = getComponentNameFromFiber(
currentlyRenderingFiber$1
);

if (!didWarnAboutUseFormState.has(componentName)) {
didWarnAboutUseFormState.add(componentName);

error(
"ReactDOM.useFormState has been deprecated and replaced by " +
"React.useActionState. Please update %s to use React.useActionState.",
componentName
);
}
}
}

function warnIfAsyncClientComponent(Component) {
{
// This dev-only check only works for detecting native async functions,
Expand Down Expand Up @@ -14580,6 +14600,7 @@ to return true:wantsResponderID| |
function useFormState(action, initialState, permalink) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
warnOnUseFormStateInDev();
return mountActionState(action, initialState);
};

Expand Down Expand Up @@ -14734,6 +14755,7 @@ to return true:wantsResponderID| |
) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
warnOnUseFormStateInDev();
return updateActionState(action);
};

Expand Down Expand Up @@ -14893,6 +14915,7 @@ to return true:wantsResponderID| |
) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
warnOnUseFormStateInDev();
return rerenderActionState(action);
};

Expand Down Expand Up @@ -30580,7 +30603,7 @@ to return true:wantsResponderID| |
return root;
}

var ReactVersion = "19.0.0-canary-7938b6a8";
var ReactVersion = "19.0.0-canary-c6651440";

function createPortal$1(
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<a9d8887935e3fc32f3bf95aea2bbf91d>>
* @generated SignedSource<<cf66f3f917e3c7a41bc8a26d1175d766>>
*/

"use strict";
Expand Down Expand Up @@ -11706,11 +11706,13 @@ to return true:wantsResponderID| |
var didWarnUncachedGetSnapshot;
var didWarnAboutUseWrappedInTryCatch;
var didWarnAboutAsyncClientComponent;
var didWarnAboutUseFormState;

{
didWarnAboutMismatchedHooksForComponent = new Set();
didWarnAboutUseWrappedInTryCatch = new Set();
didWarnAboutAsyncClientComponent = new Set();
didWarnAboutUseFormState = new Set();
} // The effect "instance" is a shared object that remains the same for the entire
// lifetime of an effect. In Rust terms, a RefCell. We use it to store the
// "destroy" function that is returned from an effect, because that is stateful.
Expand Down Expand Up @@ -11853,6 +11855,24 @@ to return true:wantsResponderID| |
}
}

function warnOnUseFormStateInDev() {
{
var componentName = getComponentNameFromFiber(
currentlyRenderingFiber$1
);

if (!didWarnAboutUseFormState.has(componentName)) {
didWarnAboutUseFormState.add(componentName);

error(
"ReactDOM.useFormState has been deprecated and replaced by " +
"React.useActionState. Please update %s to use React.useActionState.",
componentName
);
}
}
}

function warnIfAsyncClientComponent(Component) {
{
// This dev-only check only works for detecting native async functions,
Expand Down Expand Up @@ -14851,6 +14871,7 @@ to return true:wantsResponderID| |
function useFormState(action, initialState, permalink) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
warnOnUseFormStateInDev();
return mountActionState(action, initialState);
};

Expand Down Expand Up @@ -15005,6 +15026,7 @@ to return true:wantsResponderID| |
) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
warnOnUseFormStateInDev();
return updateActionState(action);
};

Expand Down Expand Up @@ -15164,6 +15186,7 @@ to return true:wantsResponderID| |
) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
warnOnUseFormStateInDev();
return rerenderActionState(action);
};

Expand Down Expand Up @@ -31020,7 +31043,7 @@ to return true:wantsResponderID| |
return root;
}

var ReactVersion = "19.0.0-canary-ebdc2fa2";
var ReactVersion = "19.0.0-canary-09379a47";

function createPortal$1(
children,
Expand Down

0 comments on commit f477752

Please sign in to comment.