Skip to content

Commit

Permalink
useFormState and useFormStatus are no longer experimental APIs and ex…
Browse files Browse the repository at this point in the history
…ist in canary and experimental builds without the `experimental_` prefix. This commit updates our docs, examples, and tests to reflect this.
  • Loading branch information
gnoff committed Oct 13, 2023
1 parent 818f716 commit c962639
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ For example, the following submit button:
```tsx filename="app/submit-button.tsx" switcher
'use client'

import { experimental_useFormStatus as useFormStatus } from 'react-dom'
import { useFormStatus } from 'react-dom'

export function SubmitButton() {
const { pending } = useFormStatus()
Expand All @@ -393,7 +393,7 @@ export function SubmitButton() {
```jsx filename="app/submit-button.jsx" switcher
'use client'

import { experimental_useFormStatus as useFormStatus } from 'react-dom'
import { useFormStatus } from 'react-dom'

export function SubmitButton() {
const { pending } = useFormStatus()
Expand Down Expand Up @@ -557,8 +557,7 @@ Then, from a Client Component, you can read this value and display an error mess
```tsx filename="app/add-form.tsx" switcher
'use client'

import { experimental_useFormState as useFormState } from 'react-dom'
import { experimental_useFormStatus as useFormStatus } from 'react-dom'
import { useFormState, useFormStatus } from 'react-dom'
import { createTodo } from '@/app/actions'

const initialState = {
Expand Down Expand Up @@ -594,8 +593,7 @@ export function AddForm() {
```jsx filename="app/add-form.jsx" switcher
'use client'

import { experimental_useFormState as useFormState } from 'react-dom'
import { experimental_useFormStatus as useFormStatus } from 'react-dom'
import { useFormState, useFormStatus } from 'react-dom'
import { createTodo } from '@/app/actions'

const initialState = {
Expand Down
2 changes: 1 addition & 1 deletion examples/next-forms/app/add-form.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { experimental_useFormState as useFormState } from 'react-dom'
import { experimental_useFormStatus as useFormStatus } from 'react-dom'
import { useFormStatus } from 'react-dom'
import { createTodo } from '@/app/actions'

const initialState = {
Expand Down
3 changes: 1 addition & 2 deletions examples/next-forms/app/delete-form.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client'

import { experimental_useFormState as useFormState } from 'react-dom'
import { experimental_useFormStatus as useFormStatus } from 'react-dom'
import { useFormState, useFormStatus } from 'react-dom'
import { deleteTodo } from '@/app/actions'

const initialState = {
Expand Down
5 changes: 2 additions & 3 deletions examples/with-fauna/components/EntryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import cn from 'classnames'
import { createEntryAction } from '@/actions/entry'
// @ts-ignore
import { experimental_useFormState as useFormState } from 'react-dom'
import { experimental_useFormStatus as useFormStatus } from 'react-dom'
import { useFormState, useFormStatus } from 'react-dom'
import LoadingSpinner from '@/components/LoadingSpinner'
import SuccessMessage from '@/components/SuccessMessage'
import ErrorMessage from '@/components/ErrorMessage'
Expand All @@ -26,7 +25,7 @@ export default function EntryForm() {

return (
<>
<form className="flex relative my-4" action={formAction}>
<form className="relative flex my-4" action={formAction}>
<input
required
className={cn(inputClasses, 'w-1/3 mr-2 px-4')}
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/core/src/react_server_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ pub fn server_components<C: Comments>(
JsWord::from("findDOMNode"),
JsWord::from("flushSync"),
JsWord::from("unstable_batchedUpdates"),
JsWord::from("experimental_useFormStatus"),
JsWord::from("experimental_useFormState"),
JsWord::from("useFormStatus"),
JsWord::from("useFormState"),
],
invalid_server_react_apis: vec![
JsWord::from("Component"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { findDOMNode, flushSync, unstable_batchedUpdates } from 'react-dom'

import {
experimental_useFormStatus,
experimental_useFormState,
} from 'react-dom'
import { useFormStatus, useFormState } from 'react-dom'

export default function () {
return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { findDOMNode, flushSync, unstable_batchedUpdates } from 'react-dom';
import { experimental_useFormStatus, experimental_useFormState } from 'react-dom';
import { useFormStatus, useFormState } from 'react-dom';
export default function() {
return null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
: ^^^^^^^^^^^^^^^^^^^^^^^
`----

x NEXT_RSC_ERR_REACT_API: experimental_useFormStatus
x NEXT_RSC_ERR_REACT_API: useFormStatus
,-[input.js:3:1]
3 | import {
4 | experimental_useFormStatus,
4 | useFormStatus,
: ^^^^^^^^^^^^^^^^^^^^^^^^^^
5 | experimental_useFormState,
5 | useFormState,
`----

x NEXT_RSC_ERR_REACT_API: experimental_useFormState
x NEXT_RSC_ERR_REACT_API: useFormState
,-[input.js:4:1]
4 | experimental_useFormStatus,
5 | experimental_useFormState,
4 | useFormStatus,
5 | useFormState,
: ^^^^^^^^^^^^^^^^^^^^^^^^^
6 | } from 'react-dom'
`----
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { findDOMNode, flushSync, unstable_batchedUpdates } from 'react-dom'

import {
experimental_useFormStatus,
experimental_useFormState,
} from 'react-dom'
import { useFormStatus, useFormState } from 'react-dom'

export default function () {
return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { findDOMNode, flushSync, unstable_batchedUpdates } from 'react-dom';
import { experimental_useFormStatus, experimental_useFormState } from 'react-dom';
import { useFormStatus, useFormState } from 'react-dom';

export default function() {
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/client/app-index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export function hydrate() {
React.startTransition(() =>
(ReactDOMClient as any).hydrateRoot(appElement, reactEl, {
...options,
experimental_formState: initialFormStateData,
formState: initialFormStateData,
})
)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ async function renderToHTMLOrFlightImpl(
nonce,
// Include hydration scripts in the HTML
bootstrapScripts: [bootstrapScript],
experimental_formState: formState,
formState,
},
})

Expand Down Expand Up @@ -825,7 +825,7 @@ async function renderToHTMLOrFlightImpl(
nonce,
// Include hydration scripts in the HTML
bootstrapScripts: [errorBootstrapScript],
experimental_formState: formState,
formState,
},
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import { experimental_useFormStatus as useFormStatus } from 'react-dom'
import { useFormStatus } from 'react-dom'
import { addToCart } from './actions'

function SubmitButton() {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/app-dir/actions/app/client/form-state/page-2/page.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client'

import { experimental_useFormState } from 'react-dom'
import { useFormState } from 'react-dom'
import { appendName } from '../actions'
import { useEffect, useState } from 'react'

export default function Page() {
const [state, appendNameFormAction] = experimental_useFormState(
const [state, appendNameFormAction] = useFormState(
appendName,
'initial-state',
'/client/form-state'
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/app-dir/actions/app/client/form-state/page.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client'

import { experimental_useFormState } from 'react-dom'
import { useFormState } from 'react-dom'
import { appendName } from './actions'
import { useEffect, useState } from 'react'

export default function Page() {
const [state, appendNameFormAction] = experimental_useFormState(
const [state, appendNameFormAction] = useFormState(
appendName,
'initial-state',
'/client/form-state'
Expand Down

0 comments on commit c962639

Please sign in to comment.