本页还没有译文
本页 8 段还没译成한국어,下面显示的是英文原文。Server Actions in Client Components
还没翻译译自英文(ai-sdk.dev)本页 8 段都还没译
You may use Server Actions in client components, but sometimes you may encounter the following issues.
Issue
It is not allowed to define inline "use server" annotated Server Actions in Client Components.
Solution
To use Server Actions in a Client Component, you can either:
- Export them from a separate file with
"use server"at the top. - Pass them down through props from a Server Component.
- Implement a combination of
createAIanduseActionshooks to access them.
Learn more about Server Actions and Mutations.
'use server';
import { generateText } from 'ai';
export async function getAnswer(question: string) {
'use server';
const { text } = await generateText({
model: 'anthropic/claude-sonnet-5.5',
prompt: question,
});
return { answer: text };
}AI 翻译查看英文原文