このガイドは、React、Vite、Tailwind CSS、Three.js、React Three Fiber、Next UIを使って効率的に開発するためのものです。主な要点とベストプラクティスを紹介します:
- コーディングスタイル
- 正確な情報を提供する、簡潔で技術的なコードを使用する 反応 典型例
- 関数型、宣言型プログラミングを使用し、クラスの使用を避ける。
- 重複コードよりも反復とモジュール化の使用を優先する。
- 補助動詞を含む説明的な変数名を使用する(例:isLoading)
- ディレクトリ名には小文字とダッシュを使用(例:components/auth-wizard)
- コンポーネントは名前付き輸出が望ましい
- JavaScript/タイプスクリプト
- 纯函数使用 “function” 关键字,省略分号
- すべてのコードにTypeScriptを使用し、型よりもインターフェースを優先し、列挙型を避け、マッピングを使用する。
- ファイル構造:エクスポートされたコンポーネント、サブコンポーネント、ヘルパー関数、静的コンテンツ、タイプ
- 条件文では不要な中括弧を使用しない。
- 簡潔な一行構文を使った簡単な条件文の表現
- エラー処理と検証
- 関数開始時のエラーとエッジケースの処理
- エラー状態の処理にはアーリーリターンを使用し、深くネストしたif文は避ける。
- 読みやすさを向上させるために、通常の実行パスを関数の最後に配置する。
- 不必要なelse文は避け、if-returnパターンを使う。
- ガード節を使用して、前提条件や無効な状態を前もって処理する。
- 適切なエラーログとユーザーフレンドリーなエラーメッセージの実装
- 一貫したエラー処理のために、カスタムエラータイプまたはエラーファクトリの使用を検討する。
- リアクト開発
- ファンクション・コンポーネントとインターフェースの使用
- 宣言的JSXの使用
- コンポーネントは、constの代わりにfunctionキーワードを使用する。
- Next UIとTailwind CSSによるコンポーネント開発とスタイリング
- レスポンシブデザインの導入
- 静的コンテンツとインターフェイスをファイルの最後に置く
- コンテンツ変数を使用して、レンダー関数の外に静的コンテンツを保存する。
- クライアント側コンポーネントをサスペンスでラッピングすることで、フォールバックを提供します。
- 非重要部品には動的負荷を使用する
- 画像の最適化:WebPフォーマットの使用、サイズデータの指定、遅延読み込み
- 予想されるエラーを戻り値としてモデル化することで、サーバー操作でのtry/catchの使用を避けることができる。
- useActionStateを使ってエラーを管理し、クライアントに返す。
- エラー境界を使用して予期しないエラーを処理し、error.tsxとglobal-error.tsxファイルを実装する。
- useActionStateとreact-hook-formを併用したフォーム検証
- tanStackQueryは常にユーザーフレンドリーなエラーを投げ、それをキャッチしてユーザーに表示します。
three.js
React、Vite、Tailwind CSS、three.js、React three fiber、Next UIのエキスパート。
主要原則
– Write concise, technical responses with accurate React examples.
– Use functional, declarative programming. Avoid classes.
– Prefer iteration and modularization over duplication.
– Use descriptive variable names with auxiliary verbs (e.g., isLoading).
– Use lowercase with dashes for directories (e.g., components/auth-wizard).
– Favor named exports for components.
– Use the Receive an Object, Return an Object (RORO) pattern.
ジャバスクリプト
– Use “function” keyword for pure functions. Omit semicolons.
– Use TypeScript for all code. Prefer interfaces over types. Avoid enums, use maps.
– File structure: Exported component, subcomponents, helpers, static content, types.
– Avoid unnecessary curly braces in conditional statements.
– For single-line statements in conditionals, omit curly braces.
– Use concise, one-line syntax for simple conditional statements (e.g., if (condition) doSomething()).
エラー処理と検証
– Prioritize error handling and edge cases:
– Handle errors and edge cases at the beginning of functions.
– Use early returns for error conditions to avoid deeply nested if statements.
– Place the happy path last in the function for improved readability.
– Avoid unnecessary else statements; use if-return pattern instead.
– Use guard clauses to handle preconditions and invalid states early.
– Implement proper error logging and user-friendly error messages.
– Consider using custom error types or error factories for consistent error handling.
反応
– Use functional components and interfaces.
– Use declarative JSX.
– Use function, not const, for components.
– Use Next UI, and Tailwind CSS for components and styling.
– Implement responsive design with Tailwind CSS.
– Implement responsive design.
– Place static content and interfaces at file end.
– Use content variables for static content outside render functions.
– Wrap client components in Suspense with fallback.
– Use dynamic loading for non-critical components.
– Optimize images: WebP format, size data, lazy loading.
– Model expected errors as return values: Avoid using try/catch for expected errors in Server Actions. Use useActionState to manage these errors and return them to the client.
– Use error boundaries for unexpected errors: Implement error boundaries using error.tsx and global-error.tsx files to handle unexpected errors and provide a fallback UI.
– Use useActionState with react-hook-form for form validation.
– Always throw user-friendly errors that tanStackQuery can catch and show to the user.