Home / Function/ getFormState() — astro Function Reference

getFormState() — astro Function Reference

Architecture documentation for the getFormState() function in server.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  4c527789_d4d5_d58b_c232_06c54369f406["getFormState()"]
  88d29d84_fc17_43e9_f02f_9b64acf73dd5["server.ts"]
  4c527789_d4d5_d58b_c232_06c54369f406 -->|defined in| 88d29d84_fc17_43e9_f02f_9b64acf73dd5
  1a376583_017c_cfcf_84e2_0bfbbc11de09["renderToStaticMarkup()"]
  1a376583_017c_cfcf_84e2_0bfbbc11de09 -->|calls| 4c527789_d4d5_d58b_c232_06c54369f406
  488bcc14_75e5_e615_82f7_f5c218b99285["isFormRequest()"]
  4c527789_d4d5_d58b_c232_06c54369f406 -->|calls| 488bcc14_75e5_e615_82f7_f5c218b99285
  style 4c527789_d4d5_d58b_c232_06c54369f406 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/integrations/react/src/server.ts lines 127–154

async function getFormState({
	result,
}: RendererContext): Promise<
	[actionResult: any, actionKey: string, actionName: string] | undefined
> {
	const { request, actionResult } = result;

	if (!actionResult) return undefined;
	if (!isFormRequest(request.headers.get('content-type'))) return undefined;

	const { searchParams } = new URL(request.url);
	const formData = await request.clone().formData();
	/**
	 * The key generated by React to identify each `useActionState()` call.
	 * @example "k511f74df5a35d32e7cf266450d85cb6c"
	 */
	const actionKey = formData.get('$ACTION_KEY')?.toString();
	/**
	 * The action name returned by an action's `toString()` property.
	 * This matches the endpoint path.
	 * @example "/_actions/blog.like"
	 */
	const actionName = searchParams.get('_action');

	if (!actionKey || !actionName) return undefined;

	return [actionResult, actionKey, actionName];
}

Domain

Subdomains

Frequently Asked Questions

What does getFormState() do?
getFormState() is a function in the astro codebase, defined in packages/integrations/react/src/server.ts.
Where is getFormState() defined?
getFormState() is defined in packages/integrations/react/src/server.ts at line 127.
What does getFormState() call?
getFormState() calls 1 function(s): isFormRequest.
What calls getFormState()?
getFormState() is called by 1 function(s): renderToStaticMarkup.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free