-
Notifications
You must be signed in to change notification settings - Fork 47.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stub for experimental_useFormStatus (#26719)
This wires up, but does not yet implement, an experimental hook called useFormStatus. The hook is imported from React DOM, not React, because it represents DOM-specific state — its return type includes FormData as one of its fields. Other renderers that implement similar methods would use their own renderer-specific types. The API is prefixed and only available in the experimental channel. It can only be used from client (browser, SSR) components, not Server Components.
- Loading branch information
Showing
8 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import {enableAsyncActions, enableFormActions} from 'shared/ReactFeatureFlags'; | ||
|
||
type FormStatusNotPending = {| | ||
pending: false, | ||
data: null, | ||
method: null, | ||
action: null, | ||
|}; | ||
|
||
type FormStatusPending = {| | ||
pending: true, | ||
data: FormData, | ||
method: string, | ||
action: string | (FormData => void | Promise<void>), | ||
|}; | ||
|
||
export type FormStatus = FormStatusPending | FormStatusNotPending; | ||
|
||
// Since the "not pending" value is always the same, we can reuse the | ||
// same object across all transitions. | ||
const sharedNotPendingObject = { | ||
pending: false, | ||
data: null, | ||
method: null, | ||
action: null, | ||
}; | ||
|
||
const NotPending: FormStatus = __DEV__ | ||
? Object.freeze(sharedNotPendingObject) | ||
: sharedNotPendingObject; | ||
|
||
export function useFormStatus(): FormStatus { | ||
if (!(enableFormActions && enableAsyncActions)) { | ||
throw new Error('Not implemented.'); | ||
} else { | ||
// TODO: This isn't fully implemented yet but we return a correctly typed | ||
// value so we can test that the API is exposed and gated correctly. The | ||
// real implementation will access the status via the dispatcher. | ||
return NotPending; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters