<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] ## useFormState app/action.tsx ``` 'use server' import { redirect } from 'next/navigation' // 定義狀態類型 type State = { message?: string; success?: boolean; } | null; // 修改 action 函數的類型定義 export async function createUser(prevState: State, formData: FormData): Promise<State> { try { const res = await fetch('https://...') const json = await res.json() if (!res.ok) { return { message: '請輸入有效的郵箱地址', success: false } } return { message: '創建成功', success: true } } catch (error) { return { message: '發生錯誤,請稍后重試', success: false } } } ``` app/page.tsx ``` 'use client' import { useFormState } from 'react-dom' import { createUser } from '@/app/actions' export default function SignupForm() { // 初始化 formState const [state, formAction] = useFormState(createUser, null) return ( <form action={formAction}> {state?.message && ( <p className={state.success ? 'text-green-500' : 'text-red-500'}> {state.message} </p> )} <input type="email" name="email" /> <button type="submit">注冊</button> </form> ) } ``` > 表單的信息會提交給acton 出來,如果有錯誤的話,會再 state 中接收 ## Error Page - 錯誤會會拋向最近一層 ### 入門 報錯 ``` import { Demo } from "."; export default function BlogPage() { throw new Error('Not implemented') return <div>Blog a <Demo /> </div> } ``` app/dashboard/error.tsx ``` 'use client' // Error boundaries must be Client Components import { useEffect } from 'react' export default function Error({ error, reset, }: { error: Error & { digest?: string } reset: () => void }) { useEffect(() => { // Log the error to an error reporting service console.error(error) }, [error]) return ( <div> <h2>Something went wrong!</h2> <button onClick={ // Attempt to recover by trying to re-render the segment () => reset() } > Try again </button> </div> ) } ``` ### global-error ``` 'use client' // Error boundaries must be Client Components export default function GlobalError({ error, reset, }: { error: Error & { digest?: string } reset: () => void }) { return ( // global-error must include html and body tags <html> <body> <h2>Something went wrong!</h2> <button onClick={() => reset()}>Try again</button> </body> </html> ) } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看