From cad3c0202592dce39445d0786743cac799631248 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Wed, 4 Oct 2023 15:58:08 -0400 Subject: [PATCH] Add back temporary `experimental_` aliases for Server Actions APIs (#27461) This adds back the `experimental_`-prefixed Server Actions APIs to the experimental builds only, so that apps that use those don't immediately break when upgrading. The APIs will log a warning to encourage people to move to the unprefixed version, or to switch to the canary release channel. We can remove these in a few weeks after we've given people a chance to upgrade. This does not affect the canary builds at all, since they never had the prefixed versions to begin with. --- packages/react-dom/index.experimental.js | 27 ++++++++++++++++++++++++ packages/react/index.experimental.js | 15 +++++++++++++ 2 files changed, 42 insertions(+) diff --git a/packages/react-dom/index.experimental.js b/packages/react-dom/index.experimental.js index c21671c8306ee..e946fee656329 100644 --- a/packages/react-dom/index.experimental.js +++ b/packages/react-dom/index.experimental.js @@ -30,3 +30,30 @@ export { preinitModule, version, } from './src/client/ReactDOM'; + +import type {FormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions'; +import {useFormStatus, useFormState} from './src/client/ReactDOM'; + +export function experimental_useFormStatus(): FormStatus { + if (__DEV__) { + console.error( + 'useFormStatus is now in canary. Remove the experimental_ prefix. ' + + 'The prefixed alias will be removed in an upcoming release.', + ); + } + return useFormStatus(); +} + +export function experimental_useFormState( + action: (S, P) => Promise, + initialState: S, + permalink?: string, +): [S, (P) => void] { + if (__DEV__) { + console.error( + 'useFormState is now in canary. Remove the experimental_ prefix. ' + + 'The prefixed alias will be removed in an upcoming release.', + ); + } + return useFormState(action, initialState, permalink); +} diff --git a/packages/react/index.experimental.js b/packages/react/index.experimental.js index f1092ff4a8778..c3d7e01adb6bd 100644 --- a/packages/react/index.experimental.js +++ b/packages/react/index.experimental.js @@ -58,3 +58,18 @@ export { useTransition, version, } from './src/React'; + +import {useOptimistic} from './src/React'; + +export function experimental_useOptimistic( + passthrough: S, + reducer: ?(S, A) => S, +): [S, (A) => void] { + if (__DEV__) { + console.error( + 'useOptimistic is now in canary. Remove the experimental_ prefix. ' + + 'The prefixed alias will be removed in an upcoming release.', + ); + } + return useOptimistic(passthrough, reducer); +}