You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/blog/2024/02/15/react-labs-what-we-have-been-working-on-february-2024.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ We refer to this broader collection of features as simply "Actions". Actions all
52
52
</form>
53
53
```
54
54
55
-
The `action` function can operate synchronously or asynchronously. You can define them on the client side using standard JavaScript or on the server with the [`'use server'`](/reference/react/use-server) directive. When using an action, React will manage the life cycle of the data submission for you, providing hooks like [`useFormStatus`](/reference/react-dom/hooks/useFormStatus), and [`useActionState`](/reference/react/useActionState) to access the current state and response of the form action.
55
+
The `action` function can operate synchronously or asynchronously. You can define them on the client side using standard JavaScript or on the server with the [`'use server'`](/reference/rsc/use-server) directive. When using an action, React will manage the life cycle of the data submission for you, providing hooks like [`useFormStatus`](/reference/react-dom/hooks/useFormStatus), and [`useActionState`](/reference/react/useActionState) to access the current state and response of the form action.
56
56
57
57
By default, Actions are submitted within a [transition](/reference/react/useTransition), keeping the current page interactive while the action is processing. Since Actions support async functions, we've also added the ability to use `async/await` in transitions. This allows you to show pending UI with the `isPending` state of a transition when an async request like `fetch` starts, and show the pending UI all the way through the update being applied.
58
58
@@ -72,7 +72,7 @@ Canaries are a change to the way we develop React. Previously, features would be
72
72
73
73
React Server Components, Asset Loading, Document Metadata, and Actions have all landed in the React Canary, and we've added docs for these features on react.dev:
74
74
75
-
-**Directives**: [`"use client"`](/reference/react/use-client) and [`"use server"`](/reference/react/use-server) are bundler features designed for full-stack React frameworks. They mark the "split points" between the two environments: `"use client"` instructs the bundler to generate a `<script>` tag (like [Astro Islands](https://docs.astro.build/en/concepts/islands/#creating-an-island)), while `"use server"` tells the bundler to generate a POST endpoint (like [tRPC Mutations](https://trpc.io/docs/concepts)). Together, they let you write reusable components that compose client-side interactivity with the related server-side logic.
75
+
-**Directives**: [`"use client"`](/reference/rsc/use-client) and [`"use server"`](/reference/rsc/use-server) are bundler features designed for full-stack React frameworks. They mark the "split points" between the two environments: `"use client"` instructs the bundler to generate a `<script>` tag (like [Astro Islands](https://docs.astro.build/en/concepts/islands/#creating-an-island)), while `"use server"` tells the bundler to generate a POST endpoint (like [tRPC Mutations](https://trpc.io/docs/concepts)). Together, they let you write reusable components that compose client-side interactivity with the related server-side logic.
76
76
77
77
-**Document Metadata**: we added built-in support for rendering [`<title>`](/reference/react-dom/components/title), [`<meta>`](/reference/react-dom/components/meta), and metadata [`<link>`](/reference/react-dom/components/link) tags anywhere in your component tree. These work the same way in all environments, including fully client-side code, SSR, and RSC. This provides built-in support for features pioneered by libraries like [React Helmet](https://github.com/nfl/react-helmet).
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/components/form.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,7 @@ export default function Search() {
93
93
94
94
### Handle form submission with a Server Action {/*handle-form-submission-with-a-server-action*/}
95
95
96
-
Render a `<form>` with an input and submit button. Pass a Server Action (a function marked with [`'use server'`](/reference/react/use-server)) to the `action` prop of form to run the function when the form is submitted.
96
+
Render a `<form>` with an input and submit button. Pass a Server Action (a function marked with [`'use server'`](/reference/rsc/use-server)) to the `action` prop of form to run the function when the form is submitted.
97
97
98
98
Passing a Server Action to `<form action>` allow users to submit forms without JavaScript enabled or before the code has loaded. This is beneficial to users who have a slow connection, device, or have JavaScript disabled and is similar to the way forms work when a URL is passed to the `action` prop.
99
99
@@ -137,7 +137,7 @@ function AddToCart({productId}) {
137
137
}
138
138
```
139
139
140
-
When `<form>` is rendered by a [Server Component](/reference/react/use-client), and a [Server Action](/reference/react/use-server) is passed to the `<form>`'s `action` prop, the form is [progressively enhanced](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement).
140
+
When `<form>` is rendered by a [Server Component](/reference/rsc/use-client), and a [Server Action](/reference/rsc/use-server) is passed to the `<form>`'s `action` prop, the form is [progressively enhanced](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement).
141
141
142
142
### Display a pending state during form submission {/*display-a-pending-state-during-form-submission*/}
143
143
To display a pending state when a form is being submitted, you can call the `useFormStatus` Hook in a component rendered in a `<form>` and read the `pending` property returned.
@@ -322,11 +322,11 @@ export default function Search() {
322
322
323
323
Displaying a form submission error message before the JavaScript bundle loads for progressive enhancement requires that:
324
324
325
-
1.`<form>` be rendered by a [Server Component](/reference/react/use-client)
326
-
1. the function passed to the `<form>`'s `action` prop be a [Server Action](/reference/react/use-server)
325
+
1.`<form>` be rendered by a [Server Component](/reference/rsc/use-client)
326
+
1. the function passed to the `<form>`'s `action` prop be a [Server Action](/reference/rsc/use-server)
327
327
1. the `useActionState` Hook be used to display the error message
328
328
329
-
`useActionState` takes two parameters: a [Server Action](/reference/react/use-server) and an initial state. `useActionState` returns two values, a state variable and an action. The action returned by `useActionState` should be passed to the `action` prop of the form. The state variable returned by `useActionState` can be used to displayed an error message. The value returned by the [Server Action](/reference/react/use-server) passed to `useActionState` will be used to update the state variable.
329
+
`useActionState` takes two parameters: a [Server Action](/reference/rsc/use-server) and an initial state. `useActionState` returns two values, a state variable and an action. The action returned by `useActionState` should be passed to the `action` prop of the form. The state variable returned by `useActionState` can be used to displayed an error message. The value returned by the [Server Action](/reference/rsc/use-server) passed to `useActionState` will be used to update the state variable.
Copy file name to clipboardExpand all lines: src/content/reference/react/use.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -55,8 +55,8 @@ The `use` API returns the value that was read from the resource like the resolve
55
55
#### Caveats {/*caveats*/}
56
56
57
57
* The `use` API must be called inside a Component or a Hook.
58
-
* When fetching data in a [Server Component](/reference/react/use-server), prefer `async` and `await` over `use`. `async` and `await` pick up rendering from the point where `await` was invoked, whereas `use` re-renders the component after the data is resolved.
59
-
* Prefer creating Promises in [Server Components](/reference/react/use-server) and passing them to [Client Components](/reference/react/use-client) over creating Promises in Client Components. Promises created in Client Components are recreated on every render. Promises passed from a Server Component to a Client Component are stable across re-renders. [See this example](#streaming-data-from-server-to-client).
58
+
* When fetching data in a [Server Component](/reference/rsc/use-server), prefer `async` and `await` over `use`. `async` and `await` pick up rendering from the point where `await` was invoked, whereas `use` re-renders the component after the data is resolved.
59
+
* Prefer creating Promises in [Server Components](/reference/rsc/use-server) and passing them to [Client Components](/reference/rsc/use-client) over creating Promises in Client Components. Promises created in Client Components are recreated on every render. Promises passed from a Server Component to a Client Component are stable across re-renders. [See this example](#streaming-data-from-server-to-client).
Copy file name to clipboardExpand all lines: src/content/reference/react/useActionState.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ canary: true
5
5
6
6
<Canary>
7
7
8
-
The `useActionState` Hook is currently only available in React's Canary and experimental channels. Learn more about [release channels here](/community/versioning-policy#all-release-channels). In addition, you need to use a framework that supports [React Server Components](/reference/react/use-client) to get the full benefit of `useActionState`.
8
+
The `useActionState` Hook is currently only available in React's Canary and experimental channels. Learn more about [release channels here](/community/versioning-policy#all-release-channels). In addition, you need to use a framework that supports [React Server Components](/reference/rsc/use-client) to get the full benefit of `useActionState`.
9
9
10
10
</Canary>
11
11
@@ -65,7 +65,7 @@ If used with a Server Action, `useActionState` allows the server's response from
65
65
66
66
* `fn`: The function to be called when the form is submitted or button pressed. When the function is called, it will receive the previous state of the form (initially the `initialState` that you pass, subsequently its previous return value) as its initial argument, followed by the arguments that a form action normally receives.
67
67
* `initialState`: The value you want the state to be initially. It can be any serializable value. This argument is ignored after the action is first invoked.
68
-
* **optional** `permalink`: A string containing the unique page URL that this form modifies. For use on pages with dynamic content (eg: feeds) in conjunction with progressive enhancement: if `fn` is a [server action](/reference/react/use-server) and the form is submitted before the JavaScript bundle loads, the browser will navigate to the specified permalink URL, rather than the current page's URL. Ensure that the same form component is rendered on the destination page (including the same action `fn` and `permalink`) so that React knows how to pass the state through. Once the form has been hydrated, this parameter has no effect.
68
+
* **optional** `permalink`: A string containing the unique page URL that this form modifies. For use on pages with dynamic content (eg: feeds) in conjunction with progressive enhancement: if `fn` is a [server action](/reference/rsc/use-server) and the form is submitted before the JavaScript bundle loads, the browser will navigate to the specified permalink URL, rather than the current page's URL. Ensure that the same form component is rendered on the destination page (including the same action `fn` and `permalink`) so that React knows how to pass the state through. Once the form has been hydrated, this parameter has no effect.
69
69
70
70
{/* TODO T164397693: link to serializable values docs once it exists */}
Copy file name to clipboardExpand all lines: src/content/reference/rsc/server-actions.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ export default function Button({onClick}) {
57
57
}
58
58
```
59
59
60
-
For more, see the docs for [`"use server"`](/reference/react/use-server).
60
+
For more, see the docs for [`"use server"`](/reference/rsc/use-server).
61
61
62
62
63
63
### Importing Server Actions from Client Components {/*importing-server-actions-from-client-components*/}
@@ -86,7 +86,7 @@ function EmptyNote() {
86
86
}
87
87
```
88
88
89
-
For more, see the docs for [`"use server"`](/reference/react/use-server).
89
+
For more, see the docs for [`"use server"`](/reference/rsc/use-server).
90
90
91
91
### Composing Server Actions with Actions {/*composing-server-actions-with-actions*/}
92
92
@@ -136,7 +136,7 @@ function UpdateName() {
136
136
137
137
This allows you to access the `isPending` state of the Server Action by wrapping it in an Action on the client.
138
138
139
-
For more, see the docs for [Calling a Server Action outside of `<form>`](/reference/react/use-server#calling-a-server-action-outside-of-form)
139
+
For more, see the docs for [Calling a Server Action outside of `<form>`](/reference/rsc/use-server#calling-a-server-action-outside-of-form)
140
140
141
141
### Form Actions with Server Actions {/*form-actions-with-server-actions*/}
142
142
@@ -161,7 +161,7 @@ function UpdateName() {
161
161
162
162
When the Form submission succeeds, React will automatically reset the form. You can add `useActionState` to access the pending state, last response, or to support progressive enhancement.
163
163
164
-
For more, see the docs for [Server Actions in Forms](/reference/react/use-server#server-actions-in-forms).
164
+
For more, see the docs for [Server Actions in Forms](/reference/rsc/use-server#server-actions-in-forms).
165
165
166
166
### Server Actions with `useActionState` {/*server-actions-with-use-action-state*/}
Copy file name to clipboardExpand all lines: src/content/reference/rsc/use-client.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -269,12 +269,12 @@ Serializable props include:
269
269
* [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) and [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
* Plain [objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object): those created with [object initializers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer), with serializable properties
272
-
* Functions that are [Server Actions](/reference/react/use-server)
272
+
* Functions that are [Server Actions](/reference/rsc/use-server)
*[Functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) that are not exported from client-marked modules or marked with [`'use server'`](/reference/react/use-server)
277
+
*[Functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) that are not exported from client-marked modules or marked with [`'use server'`](/reference/rsc/use-server)
* Objects that are instances of any class (other than the built-ins mentioned) or objects with [a null prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#null-prototype_objects)
280
280
* Symbols not registered globally, ex. `Symbol('my new symbol')`
Copy file name to clipboardExpand all lines: src/content/reference/rsc/use-server.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ Instead of individually marking functions with `'use server'`, you can add the d
41
41
#### Caveats {/*caveats*/}
42
42
*`'use server'` must be at the very beginning of their function or module; above any other code including imports (comments above directives are OK). They must be written with single or double quotes, not backticks.
43
43
*`'use server'` can only be used in server-side files. The resulting Server Actions can be passed to Client Components through props. See supported [types for serialization](#serializable-parameters-and-return-values).
44
-
* To import a Server Action from [client code](/reference/react/use-client), the directive must be used on a module level.
44
+
* To import a Server Action from [client code](/reference/rsc/use-client), the directive must be used on a module level.
45
45
* Because the underlying network calls are always asynchronous, `'use server'` can only be used on async functions.
46
46
* Always treat arguments to Server Actions as untrusted input and authorize any mutations. See [security considerations](#security).
47
47
* Server Actions should be called in a [Transition](/reference/react/useTransition). Server Actions passed to [`<form action>`](/reference/react-dom/components/form#props) or [`formAction`](/reference/react-dom/components/input#props) will automatically be called in a transition.
@@ -95,7 +95,7 @@ Notably, these are not supported:
95
95
* Symbols not registered globally, ex. `Symbol('my new symbol')`
96
96
97
97
98
-
Supported serializable return values are the same as [serializable props](/reference/react/use-client#passing-props-from-server-to-client-components) for a boundary Client Component.
98
+
Supported serializable return values are the same as [serializable props](/reference/rsc/use-client#passing-props-from-server-to-client-components) for a boundary Client Component.
99
99
100
100
101
101
## Usage {/*usage*/}
@@ -171,7 +171,7 @@ function UsernameForm() {
171
171
}
172
172
```
173
173
174
-
Note that like most Hooks, `useActionState` can only be called in <CodeStepstep={1}>[client code](/reference/react/use-client)</CodeStep>.
174
+
Note that like most Hooks, `useActionState` can only be called in <CodeStepstep={1}>[client code](/reference/rsc/use-client)</CodeStep>.
175
175
176
176
### Calling a Server Action outside of `<form>` {/*calling-a-server-action-outside-of-form*/}
0 commit comments