Skip to content

Commit 627e245

Browse files
yanthomasdevsarah11918ArmandPhilippot
authored
Update experimental React Actions helpers to stable (#12402)
Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Armand Philippot <[email protected]>
1 parent 853ccd7 commit 627e245

File tree

1 file changed

+13
-13
lines changed
  • src/content/docs/en/guides/integrations-guide

1 file changed

+13
-13
lines changed

src/content/docs/en/guides/integrations-guide/react.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,30 +115,30 @@ To use your first React component in Astro, head to our [UI framework documentat
115115
* 💧 client-side hydration options, and
116116
* 🤝 opportunities to mix and nest frameworks together
117117

118-
## Integrate Actions with `useActionState()` (experimental)
118+
## Integrate Actions with `useActionState()`
119119

120-
The `@astrojs/react` integration provides two experimental functions for use with [Astro Actions][astro-actions]: `experimental_withState()` and `experimental_getActionState()`.
120+
The `@astrojs/react` integration provides two functions for use with [Astro Actions][astro-actions]: `withState()` and `getActionState()`.
121121

122122
These are used with [React's useActionState() hook](https://react.dev/reference/react/useActionState) to read and update client-side state when triggering actions during form submission.
123123

124-
### `experimental_withState()`
124+
### `withState()`
125125

126126
<p>
127127

128128
**Type:** `(action: FormFn<T>) => (state: T, formData: FormData) => FormFn<T>`<br />
129-
<Since v="4.3.2" />
129+
<Since v="4.4.0" pkg="@astrojs/react" />
130130
</p>
131131

132-
You can pass `experimental_withState()` and the action you want to trigger to React's `useActionState()` hook as the form action function. The example below passes a `like` action to increase a counter along with an initial state of `0` likes.
132+
You can pass `withState()` and the action you want to trigger to React's `useActionState()` hook as the form action function. The example below passes a `like` action to increase a counter along with an initial state of `0` likes.
133133

134134
```jsx title="Like.tsx" ins={2,7} "useActionState"
135135
import { actions } from 'astro:actions';
136-
import { experimental_withState } from '@astrojs/react/actions';
136+
import { withState } from '@astrojs/react/actions';
137137
import { useActionState } from "react";
138138

139139
export function Like({ postId }: { postId: string }) {
140140
const [state, action, pending] = useActionState(
141-
experimental_withState(actions.like),
141+
withState(actions.like),
142142
{ data: 0, error: undefined }, // initial likes and errors
143143
);
144144

@@ -151,32 +151,32 @@ export function Like({ postId }: { postId: string }) {
151151
}
152152
```
153153

154-
The `experimental_withState()` function will match the action's types with React's expectations and preserve metadata used for progressive enhancement, allowing it to work even when JavaScript is disabled on the user's device.
154+
The `withState()` function will match the action's types with React's expectations and preserve metadata used for progressive enhancement, allowing it to work even when JavaScript is disabled on the user's device.
155155

156-
### `experimental_getActionState()`
156+
### `getActionState()`
157157

158158
<p>
159159

160160
**Type:** `(context: ActionAPIContext) => Promise<T>`<br />
161-
<Since v="4.3.2" />
161+
<Since v="4.4.0" pkg="@astrojs/react" />
162162
</p>
163163

164-
You can access the state stored by `useActionState()` on the server in your action `handler` with `experimental_getActionState()`. It accepts the [Astro API context](/en/reference/api-reference/#the-context-object), and optionally, you can apply a type to the result.
164+
You can access the state stored by `useActionState()` on the server in your action `handler` with `getActionState()`. It accepts the [Astro API context](/en/reference/api-reference/#the-context-object), and optionally, you can apply a type to the result.
165165

166166
The example below gets the current value of likes from a counter, typed as a number, in order to create an incrementing `like` action:
167167

168168
```ts title="actions.ts" ins={3,11}
169169
import { defineAction, type SafeResult } from 'astro:actions';
170170
import { z } from 'astro:schema';
171-
import { experimental_getActionState } from '@astrojs/react/actions';
171+
import { getActionState } from '@astrojs/react/actions';
172172

173173
export const server = {
174174
like: defineAction({
175175
input: z.object({
176176
postId: z.string(),
177177
}),
178178
handler: async ({ postId }, ctx) => {
179-
const { data: currentLikes = 0, error } = await experimental_getActionState<SafeResult<any, number>>(ctx);
179+
const { data: currentLikes = 0, error } = await getActionState<SafeResult<any, number>>(ctx);
180180

181181
// handle errors
182182
if (error) throw error;

0 commit comments

Comments
 (0)